aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util.c16
-rw-r--r--src/util/io.h14
2 files changed, 28 insertions, 2 deletions
diff --git a/src/util.c b/src/util.c
index 35d7ee6..b87e9b5 100644
--- a/src/util.c
+++ b/src/util.c
@@ -140,6 +140,22 @@ readall(int fd, void *buf, size_t n)
return r;
}
+int
+pwriteall(int fd, void *buf, size_t n, size_t ptr)
+{
+ char *buffer = buf;
+ ssize_t r;
+ while (n) {
+ r = pwrite(fd, buffer, n, ptr);
+ if (r < 0)
+ return -1;
+ buffer += (size_t)r;
+ n -= (size_t)r;
+ ptr += (size_t)r;
+ }
+ return 0;
+}
+
static inline pid_t
enfork(int status)
diff --git a/src/util/io.h b/src/util/io.h
index ac326c8..81b8f51 100644
--- a/src/util/io.h
+++ b/src/util/io.h
@@ -1,7 +1,8 @@
/* See LICENSE file for copyright and license details. */
-#define ewriteall(...) enwriteall(1, __VA_ARGS__)
-#define ereadall(...) enreadall(1, __VA_ARGS__)
+#define ewriteall(...) enwriteall(1, __VA_ARGS__)
+#define ereadall(...) enreadall(1, __VA_ARGS__)
+#define epwriteall(...) enpwriteall(1, __VA_ARGS__)
int writeall(int fd, void *buf, size_t n);
@@ -22,3 +23,12 @@ enreadall(int status, int fd, void *buf, size_t n, const char *fname)
enprintf(status, "read %s:", fname);
return (size_t)r;
}
+
+int pwriteall(int fd, void *buf, size_t n, size_t ptr);
+
+static inline void
+enpwriteall(int status, int fd, void *buf, size_t n, size_t ptr, const char *fname)
+{
+ if (pwriteall(fd, buf, n, ptr))
+ enprintf(status, "pwrite %s:", fname);
+}