From f3e452a35ab5fd1808be7a50652b54dc3222ba6e Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Mon, 8 Jan 2007 02:49:39 -0500 Subject: Add rewrite(), writeall(),and xwrite() to match the read versions. --- lib/functions.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'lib/functions.c') diff --git a/lib/functions.c b/lib/functions.c index 990c34fa..e37887ed 100644 --- a/lib/functions.c +++ b/lib/functions.c @@ -165,13 +165,21 @@ FILE *xfopen(char *path, char *mode) // Read from file handle, retrying if interrupted. ssize_t reread(int fd, void *buf, size_t count) { - ssize_t len; for (;;) { - len = read(fd, buf, count); + ssize_t len = read(fd, buf, count); if (len >= 0 || errno != EINTR) return len; } } +// Write to file handle, retrying if interrupted. +ssize_t rewrite(int fd, void *buf, size_t count) +{ + for (;;) { + ssize_t len = write(fd, buf, count); + if (len >= 0 || errno != EINTR) return len; + } +} + // Keep reading until full or EOF ssize_t readall(int fd, void *buf, size_t count) { @@ -186,12 +194,31 @@ ssize_t readall(int fd, void *buf, size_t count) return count; } +// Keep writing until done or EOF +ssize_t writeall(int fd, void *buf, size_t count) +{ + size_t len = 0; + while (len