X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=pkt-line.c;h=f5d00863a6234c16db33637d19fefd2014780e87;hb=6e13921b4f7adcc7316a76c0c4955b85b1589a65;hp=b4cb7e2756dcc52c17aebf4c0fc6adc7b415ef3c;hpb=5f5dbd719d0d8ec136f32a0a56674902bd85f72f;p=git.git diff --git a/pkt-line.c b/pkt-line.c index b4cb7e275..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 @@ -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, (char *) buffer + n, size - n); - if (ret < 0) - die("read error (%s)", strerror(errno)); - if (!ret) - die("The remote end hung up unexpectedly"); - 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)