pkt-line: drop safe_write function
This is just write_or_die by another name. The one distinction is that write_or_die will treat EPIPE specially by suppressing error messages. That's fine, as we die by SIGPIPE anyway (and in the off chance that it is disabled, write_or_die will simulate it). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Feb 20, 2013 at 15:01 UTC
cdf4fb8e332f9641ac1ca95e999fe98251d31392
10 files changed
+19
-35
builtin/receive-pack.c
+1
-1
@@ -932,7 +932,7 @@ static void report(struct command *commands, const char *unpack_status)
932
if (use_sideband)
933
send_sideband(1, 1, buf.buf, buf.len, use_sideband);
934
else
935
- safe_write(1, buf.buf, buf.len);
935
+ write_or_die(1, buf.buf, buf.len);
936
strbuf_release(&buf);
937
}
938
builtin/send-pack.c
+1
-1
@@ -79,7 +79,7 @@ static void print_helper_status(struct ref *ref)
79
}
80
strbuf_addch(&buf, '\n');
81
82
- safe_write(1, buf.buf, buf.len);
82
+ write_or_die(1, buf.buf, buf.len);
83
}
84
strbuf_release(&buf);
85
}
fetch-pack.c
+1
-1
@@ -247,7 +247,7 @@ static void send_request(struct fetch_pack_args *args,
247
send_sideband(fd, -1, buf->buf, buf->len, LARGE_PACKET_MAX);
248
packet_flush(fd);
249
} else
250
- safe_write(fd, buf->buf, buf->len);
250
+ write_or_die(fd, buf->buf, buf->len);
251
}
252
253
static void insert_one_alternate_ref(const struct ref *ref, void *unused)
http-backend.c
+4
-4
@@ -70,7 +70,7 @@ static void format_write(int fd, const char *fmt, ...)
70
if (n >= sizeof(buffer))
71
die("protocol error: impossibly long line");
72
73
- safe_write(fd, buffer, n);
73
+ write_or_die(fd, buffer, n);
74
}
75
76
static void http_status(unsigned code, const char *msg)
@@ -111,7 +111,7 @@ static void hdr_cache_forever(void)
111
112
static void end_headers(void)
113
{
114
- safe_write(1, "\r\n", 2);
114
+ write_or_die(1, "\r\n", 2);
115
}
116
117
__attribute__((format (printf, 1, 2)))
@@ -157,7 +157,7 @@ static void send_strbuf(const char *type, struct strbuf *buf)
157
hdr_int(content_length, buf->len);
158
hdr_str(content_type, type);
159
end_headers();
160
- safe_write(1, buf->buf, buf->len);
160
+ write_or_die(1, buf->buf, buf->len);
161
}
162
163
static void send_local_file(const char *the_type, const char *name)
@@ -185,7 +185,7 @@ static void send_local_file(const char *the_type, const char *name)
185
die_errno("Cannot read '%s'", p);
186
if (!n)
187
break;
188
- safe_write(1, buf, n);
188
+ write_or_die(1, buf, n);
189
}
190
close(fd);
191
free(buf);
pkt-line.c
+2
-19
@@ -46,23 +46,6 @@ static void packet_trace(const char *buf, unsigned int len, int write)
46
strbuf_release(&out);
47
}
48
49
-ssize_t safe_write(int fd, const void *buf, ssize_t n)
50
-{
51
- ssize_t nn = n;
52
- while (n) {
53
- int ret = xwrite(fd, buf, n);
54
- if (ret > 0) {
55
- buf = (char *) buf + ret;
56
- n -= ret;
57
- continue;
58
- }
59
- if (!ret)
60
- die("write error (disk full?)");
61
- die_errno("write error");
62
- }
63
- return nn;
64
-}
65
-
49
/*
50
* If we buffered things up above (we don't, but we should),
51
* we'd flush it here
@@ -70,7 +53,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n)
53
void packet_flush(int fd)
54
{
55
packet_trace("0000", 4, 1);
73
- safe_write(fd, "0000", 4);
56
+ write_or_die(fd, "0000", 4);
57
}
58
59
void packet_buf_flush(struct strbuf *buf)
@@ -106,7 +89,7 @@ void packet_write(int fd, const char *fmt, ...)
89
va_start(args, fmt);
90
n = format_packet(fmt, args);
91
va_end(args);
109
- safe_write(fd, buffer, n);
92
+ write_or_die(fd, buffer, n);
93
}
94
95
void packet_buf_write(struct strbuf *buf, const char *fmt, ...)
pkt-line.h
-1
@@ -27,6 +27,5 @@ void packet_buf_write(struct strbuf *buf, const char *fmt, ...) __attribute__((f
27
int packet_read_line(int fd, char *buffer, unsigned size);
28
int packet_read(int fd, char *buffer, unsigned size);
29
int packet_get_line(struct strbuf *out, char **src_buf, size_t *src_len);
30
-ssize_t safe_write(int, const void *, ssize_t);
30
31
#endif
remote-curl.c
+2
-2
@@ -685,7 +685,7 @@ static int fetch_git(struct discovery *heads,
685
686
err = rpc_service(&rpc, heads);
687
if (rpc.result.len)
688
- safe_write(1, rpc.result.buf, rpc.result.len);
688
+ write_or_die(1, rpc.result.buf, rpc.result.len);
689
strbuf_release(&rpc.result);
690
strbuf_release(&preamble);
691
free(depth_arg);
@@ -805,7 +805,7 @@ static int push_git(struct discovery *heads, int nr_spec, char **specs)
805
806
err = rpc_service(&rpc, heads);
807
if (rpc.result.len)
808
- safe_write(1, rpc.result.buf, rpc.result.len);
808
+ write_or_die(1, rpc.result.buf, rpc.result.len);
809
strbuf_release(&rpc.result);
810
free(argv);
811
return err;
send-pack.c
+1
-1
@@ -280,7 +280,7 @@ int send_pack(struct send_pack_args *args,
280
send_sideband(out, -1, req_buf.buf, req_buf.len, LARGE_PACKET_MAX);
281
}
282
} else {
283
- safe_write(out, req_buf.buf, req_buf.len);
283
+ write_or_die(out, req_buf.buf, req_buf.len);
284
packet_flush(out);
285
}
286
strbuf_release(&req_buf);
sideband.c
+5
-4
@@ -1,3 +1,4 @@
1
+#include "cache.h"
2
#include "pkt-line.h"
3
#include "sideband.h"
4
@@ -108,7 +109,7 @@ int recv_sideband(const char *me, int in_stream, int out)
109
} while (len);
110
continue;
111
case 1:
111
- safe_write(out, buf + pf+1, len);
112
+ write_or_die(out, buf + pf+1, len);
113
continue;
114
default:
115
fprintf(stderr, "%s: protocol error: bad band #%d\n",
@@ -138,12 +139,12 @@ ssize_t send_sideband(int fd, int band, const char *data, ssize_t sz, int packet
139
if (0 <= band) {
140
sprintf(hdr, "%04x", n + 5);
141
hdr[4] = band;
141
- safe_write(fd, hdr, 5);
142
+ write_or_die(fd, hdr, 5);
143
} else {
144
sprintf(hdr, "%04x", n + 4);
144
- safe_write(fd, hdr, 4);
145
+ write_or_die(fd, hdr, 4);
146
}
146
- safe_write(fd, p, n);
147
+ write_or_die(fd, p, n);
148
p += n;
149
sz -= n;
150
}
upload-pack.c
+2
-1
@@ -69,7 +69,8 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
69
xwrite(fd, data, sz);
70
return sz;
71
}
72
- return safe_write(fd, data, sz);
72
+ write_or_die(fd, data, sz);
73
+ return sz;
74
}
75
76
static FILE *pack_pipe = NULL;