From 901637760b4206e968e73dd5ff7430c107c27b57 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 18 Jan 2007 21:54:08 -0500 Subject: Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which shouldn't be a problem if we register signal handlers with sigaction(SA_RESTART) Straighten out count and len (I generally consistently use "count" for the current progress and "len" for the total, but this time I got them backwards for some reason and don't want to confuse myself in future.) --- lib/functions.c | 57 ++++++++++++++++++++----------------------------------- lib/lib.h | 12 +++++------- lib/portability.h | 6 ++++++ toys.h | 3 ++- toys/catv.c | 2 +- 5 files changed, 35 insertions(+), 45 deletions(-) diff --git a/lib/functions.c b/lib/functions.c index 98a344a2..ce3edccc 100644 --- a/lib/functions.c +++ b/lib/functions.c @@ -174,30 +174,12 @@ FILE *xfopen(char *path, char *mode) return f; } -// Read from file handle, retrying if interrupted. -ssize_t reread(int fd, void *buf, size_t count) -{ - for (;;) { - 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) +ssize_t readall(int fd, void *buf, size_t len) { - size_t len = 0; - while (len +#define fdprintf(...) dprintf(__VA_ARGS__) + #include #if __BYTE_ORDER == __BIG_ENDIAN diff --git a/toys.h b/toys.h index 27647c93..403388ed 100644 --- a/toys.h +++ b/toys.h @@ -6,6 +6,8 @@ * Licensed under GPL version 2, see file LICENSE in this tarball for details. */ +#include "lib/portability.h" + #include #include #include @@ -26,7 +28,6 @@ #include #include "lib/lib.h" -#include "lib/portability.h" #include "gen_config.h" #include "toys/toylist.h" diff --git a/toys/catv.c b/toys/catv.c index e37f307b..9097c065 100644 --- a/toys/catv.c +++ b/toys/catv.c @@ -27,7 +27,7 @@ int catv_main(void) else for(;;) { int i, res; - res = reread(fd, toybuf, sizeof(toybuf)); + res = read(fd, toybuf, sizeof(toybuf)); if (res < 0) retval = EXIT_FAILURE; if (res < 1) break; for (i=0; i