X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=pkt-line.c;h=c1e81f976f26726db2432f72f7356087a6e3a7d8;hb=ddaf73141c03aeaab5e8cf5fadaf8b7ebad7955b;hp=69473046bf717c9b97470d7652c15377dd9fc9d5;hpb=1301c6eb412e7c5511b952a12e42c70ad56f028b;p=git.git diff --git a/pkt-line.c b/pkt-line.c index 69473046b..c1e81f976 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -16,21 +16,21 @@ * The writing side could use stdio, but since the reading * side can't, we stay with pure read/write interfaces. */ -static void safe_write(int fd, const void *buf, unsigned n) +ssize_t safe_write(int fd, const void *buf, ssize_t n) { + ssize_t nn = n; while (n) { - int ret = write(fd, buf, n); + int ret = xwrite(fd, buf, n); if (ret > 0) { - buf += ret; + buf = (char *) buf + ret; n -= ret; continue; } if (!ret) die("write error (disk full?)"); - if (errno == EAGAIN || errno == EINTR) - continue; die("write error (%s)", strerror(errno)); } + return nn; } /* @@ -68,12 +68,9 @@ static void safe_read(int fd, void *buffer, unsigned size) int n = 0; while (n < size) { - int ret = read(fd, buffer + n, size - n); - if (ret < 0) { - if (errno == EINTR || errno == EAGAIN) - continue; + int ret = xread(fd, (char *) buffer + n, size - n); + if (ret < 0) die("read error (%s)", strerror(errno)); - } if (!ret) die("unexpected EOF"); n += ret;