about summary refs log tree commit diff
path: root/src/util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index d7c1fe60e15a..a16643022a9d 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;
+    }
+}