X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=pkt-line.c;h=f5d00863a6234c16db33637d19fefd2014780e87;hb=7f0475c308625fb9e4cbbad8dc665983571cc5cf;hp=3d724acf23fab5e8a8e3dd5b1dce957ea1d4a9d3;hpb=583b7ea31b7c16f872b178d541591ab816d16f85;p=git.git diff --git a/pkt-line.c b/pkt-line.c index 3d724acf2..f5d00863a 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -5,7 +5,7 @@ * Write a packetized stream, where each line is preceded by * its length (including the header) as a 4-byte hex number. * A length of 'zero' means end of stream (and a length of 1-3 - * would be an error). + * would be an error). * * This is all pretty stupid, but we use this packetized line * format to make a streaming format possible without ever @@ -22,7 +22,7 @@ ssize_t safe_write(int fd, const void *buf, ssize_t n) while (n) { int ret = xwrite(fd, buf, n); if (ret > 0) { - buf += ret; + buf = (char *) buf + ret; n -= ret; continue; } @@ -65,16 +65,11 @@ void packet_write(int fd, const char *fmt, ...) static void safe_read(int fd, void *buffer, unsigned size) { - int n = 0; - - while (n < size) { - int ret = xread(fd, buffer + n, size - n); - if (ret < 0) - die("read error (%s)", strerror(errno)); - if (!ret) - die("unexpected EOF"); - n += ret; - } + ssize_t ret = read_in_full(fd, buffer, size); + if (ret < 0) + die("read error (%s)", strerror(errno)); + else if (ret < size) + die("The remote end hung up unexpectedly"); } int packet_read_line(int fd, char *buffer, unsigned size)