From 7984cfc7c18c85c5db42c5c7d57927b12c846ce0 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Sun, 20 Jul 2003 21:11:43 +0000 Subject: * Argh, another short-write problem. Added wrappers around read()/write() to fix this once and for all. --- src/util.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/util.cc') diff --git a/src/util.cc b/src/util.cc index d7c1fe60e1..a16643022a 100644 --- a/src/util.cc +++ b/src/util.cc @@ -159,3 +159,26 @@ void debug(const format & f) { msg(format("debug: %1%") % f.str()); } + + +void readFull(int fd, unsigned char * buf, size_t count) +{ + while (count) { + ssize_t res = read(fd, (char *) buf, count); + if (res == -1) throw SysError("reading from file"); + if (res == 0) throw Error("unexpected end-of-file"); + count -= res; + buf += res; + } +} + + +void writeFull(int fd, const unsigned char * buf, size_t count) +{ + while (count) { + ssize_t res = write(fd, (char *) buf, count); + if (res == -1) throw SysError("writing to file"); + count -= res; + buf += res; + } +} -- cgit 1.4.1