summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2002-10-08 07:11:03 +0000
committerJim Meyering <jim@meyering.net>2002-10-08 07:11:03 +0000
commitb82563de581463ce06d123e448c2cef746646d1a (patch)
treef7a74862b2675a002335d546d0ea0807f2f81ad9 /src
parentf99306fcd54bc86121344c5c3691f5ccd3a1074a (diff)
downloadcoreutils-b82563de581463ce06d123e448c2cef746646d1a.tar.xz
(sysv_sum_file): Adapt to new safe_read ABI.
Diffstat (limited to 'src')
-rw-r--r--src/sum.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/sum.c b/src/sum.c
index 3ce48f439..d5e667a0c 100644
--- a/src/sum.c
+++ b/src/sum.c
@@ -151,14 +151,13 @@ sysv_sum_file (const char *file, int print_name)
{
int fd;
unsigned char buf[8192];
- register int bytes_read;
uintmax_t total_bytes = 0;
char hbuf[LONGEST_HUMAN_READABLE + 1];
int r;
int checksum;
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
- register unsigned int s = 0;
+ unsigned int s = 0;
if (STREQ (file, "-"))
{
@@ -177,23 +176,27 @@ sysv_sum_file (const char *file, int print_name)
/* Need binary I/O, or else byte counts and checksums are incorrect. */
SET_BINARY (fd);
- while ((bytes_read = safe_read (fd, buf, sizeof buf)) > 0)
+ while (1)
{
- register int i;
+ size_t i;
+ size_t bytes_read = safe_read (fd, buf, sizeof buf);
+
+ if (bytes_read == 0)
+ break;
+
+ if (bytes_read == SAFE_READ_ERROR)
+ {
+ error (0, errno, "%s", file);
+ if (!STREQ (file, "-"))
+ close (fd);
+ return -1;
+ }
for (i = 0; i < bytes_read; i++)
s += buf[i];
total_bytes += bytes_read;
}
- if (bytes_read < 0)
- {
- error (0, errno, "%s", file);
- if (!STREQ (file, "-"))
- close (fd);
- return -1;
- }
-
if (!STREQ (file, "-") && close (fd) == -1)
{
error (0, errno, "%s", file);