[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug-gnulib] merging/factoring safe-read.c and safe-write.c
From: |
Jim Meyering |
Subject: |
[Bug-gnulib] merging/factoring safe-read.c and safe-write.c |
Date: |
Tue, 03 Dec 2002 11:50:16 +0100 |
I really prefer not to have to make nearly-identical changes in two places,
so have merged safe-read.c and safe-write.c.
What do you think of these?
safe-read.c
Description: Text Data
safe-write.c
Description: Text Data
Note the diffs between these two files:
[ One nit; I've changed SAFE_READ_ERROR to SAFE_READ_WRITE_ERROR
Do any of you prefer to have separate SAFE_READ_ERROR and SAFE_WRITE_ERROR
symbols? ]
--- safe-read.c 2002-12-03 11:48:18.000000000 +0100
+++ safe-write.c 2002-12-03 11:48:26.000000000 +0100
@@ -1,4 +1,4 @@
-/* An interface to read that retries after interrupts.
+/* An interface to 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
@@ -20,7 +20,7 @@
#endif
/* Specification. */
-#include "safe-read.h"
+#include "safe-write.h"
/* Get ssize_t. */
#include <sys/types.h>
@@ -57,25 +57,25 @@ extern int errno;
# 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,
+/* Write up to COUNT bytes at BUF to descriptor FD, retrying if interrupted.
+ Return the actual number of bytes written, zero for EOF,
or SAFE_READ_WRITE_ERROR upon error. */
size_t
-safe_read (int fd, void *buf, size_t count)
+safe_write (int fd, const void *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
+ Note that in any case, write may succeed, yet 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 = write (fd, buf, count);
}
while (result < 0 && IS_EINTR (errno));
-----------------------------------------
I want to generate one from the other, or maybe generate both from a
template, as is already done to get stat.c and lstat.c from xstat.in.
Any objections?