aboutsummaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util.c12
-rw-r--r--src/util/io.h16
2 files changed, 25 insertions, 3 deletions
diff --git a/src/util.c b/src/util.c
index 6c1bd0a..92b4d20 100644
--- a/src/util.c
+++ b/src/util.c
@@ -157,6 +157,18 @@ pwriteall(int fd, void *buf, size_t n, size_t ptr)
return 0;
}
+int
+writezeroes(int fd, void *buf, size_t bufsize, size_t n)
+{
+ size_t p, m;
+ for (p = 0; p < n; p += m) {
+ m = bufsize < n - p ? bufsize : n - p;
+ if (writeall(fd, buf, m))
+ return -1;
+ }
+ return 0;
+}
+
static inline pid_t
enfork(int status)
diff --git a/src/util/io.h b/src/util/io.h
index 81b8f51..44e222d 100644
--- a/src/util/io.h
+++ b/src/util/io.h
@@ -1,8 +1,9 @@
/* See LICENSE file for copyright and license details. */
-#define ewriteall(...) enwriteall(1, __VA_ARGS__)
-#define ereadall(...) enreadall(1, __VA_ARGS__)
-#define epwriteall(...) enpwriteall(1, __VA_ARGS__)
+#define ewriteall(...) enwriteall(1, __VA_ARGS__)
+#define ereadall(...) enreadall(1, __VA_ARGS__)
+#define epwriteall(...) enpwriteall(1, __VA_ARGS__)
+#define ewritezeroes(...) enwritezeroes(1, __VA_ARGS__)
int writeall(int fd, void *buf, size_t n);
@@ -32,3 +33,12 @@ enpwriteall(int status, int fd, void *buf, size_t n, size_t ptr, const char *fna
if (pwriteall(fd, buf, n, ptr))
enprintf(status, "pwrite %s:", fname);
}
+
+int writezeroes(int fd, void *buf, size_t bufsize, size_t n);
+
+static inline void
+enwritezeroes(int status, int fd, void *buf, size_t bufsize, size_t n, const char *fname)
+{
+ if (writezeroes(fd, buf, bufsize, n))
+ enprintf(status, "write %s:", fname);
+}