# HG changeset patch # User Jim Meyering # Date 1038988976 0 # Node ID 9294b143dc8343c0f8593e0efd3be61499a24c2a # Parent 02d9405a03545ed16f953b6f2cc15a8d77abc68c Rework so that it may serve to define safe_write, too. diff --git a/lib/safe-read.c b/lib/safe-read.c --- 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 #endif -/* Specification. */ -#include "safe-read.h" - /* Get ssize_t. */ #include #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));