Mercurial > hg > octave-nkf > gnulib-hg
changeset 4056:9294b143dc83
Rework so that it may serve to define safe_write, too.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Wed, 04 Dec 2002 08:02:56 +0000 |
parents | 02d9405a0354 |
children | 9d51dd8de223 |
files | lib/safe-read.c |
diffstat | 1 files changed, 21 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/safe-read.c +++ b/lib/safe-read.c @@ -1,4 +1,4 @@ -/* An interface to read that retries after interrupts. +/* An interface to read and write that retries after interrupts. Copyright (C) 1993, 1994, 1998, 2002 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify @@ -19,9 +19,6 @@ # include <config.h> #endif -/* Specification. */ -#include "safe-read.h" - /* Get ssize_t. */ #include <sys/types.h> #if HAVE_UNISTD_H @@ -57,25 +54,38 @@ # define INT_MAX TYPE_MAXIMUM (int) #endif -/* Read up to COUNT bytes at BUF from descriptor FD, retrying if interrupted. - Return the actual number of bytes read, zero for EOF, or SAFE_READ_ERROR - upon error. */ +#ifdef SAFE_WRITE +# include "safe-write.h" +# define safe_rw safe_write +# define rw write +#else +# include "safe-read.h" +# define safe_rw safe_read +# define rw read +# undef const +# define const /* empty */ +#endif + +/* Read(write) up to COUNT bytes at BUF from(to) descriptor FD, retrying if + interrupted. Return the actual number of bytes read(written), zero for EOF, + or SAFE_READ_ERROR(SAFE_WRITE_ERROR) upon error. */ size_t -safe_read (int fd, void *buf, size_t count) +safe_rw (int fd, void const *buf, size_t count) { ssize_t result; /* POSIX limits COUNT to SSIZE_MAX, but we limit it further, requiring that COUNT <= INT_MAX, to avoid triggering a bug in Tru64 5.1. When decreasing COUNT, keep the file pointer block-aligned. - Note that in any case, read may succeed, yet read fewer than COUNT - bytes, so the caller must be prepared to handle partial results. */ + Note that in any case, read(write) may succeed, yet read(write) + fewer than COUNT bytes, so the caller must be prepared to handle + partial results. */ if (count > INT_MAX) count = INT_MAX & ~8191; do { - result = read (fd, buf, count); + result = rw (fd, buf, count); } while (result < 0 && IS_EINTR (errno));