diff options
author | Jim Meyering <jim@meyering.net> | 2002-10-09 15:07:52 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2002-10-09 15:07:52 +0000 |
commit | e995dcb2d5177d64fa5711695f625b605b5bd265 (patch) | |
tree | 9a817eed416fee9061c2ca04027d9a03f01f95c4 /src | |
parent | 7db0a344887500e3139f0c2e16b452f6d302a6b4 (diff) | |
download | coreutils-e995dcb2d5177d64fa5711695f625b605b5bd265.tar.xz |
(wc): Adapt to new safe_read ABI.
Diffstat (limited to 'src')
-rw-r--r-- | src/wc.c | 51 |
1 files changed, 28 insertions, 23 deletions
@@ -191,7 +191,7 @@ static void wc (int fd, const char *file) { char buf[BUFFER_SIZE + 1]; - ssize_t bytes_read; + size_t bytes_read; uintmax_t lines, words, chars, bytes, linelength; int count_bytes, count_chars, count_complicated; @@ -244,13 +244,14 @@ wc (int fd, const char *file) { while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0) { + if (bytes_read == SAFE_READ_ERROR) + { + error (0, errno, "%s", file); + exit_status = 1; + break; + } bytes += bytes_read; } - if (bytes_read < 0) - { - error (0, errno, "%s", file); - exit_status = 1; - } } } else if (!count_chars && !count_complicated) @@ -261,6 +262,13 @@ wc (int fd, const char *file) { register char *p = buf; + if (bytes_read == SAFE_READ_ERROR) + { + error (0, errno, "%s", file); + exit_status = 1; + break; + } + while ((p = memchr (p, '\n', (buf + bytes_read) - p))) { ++p; @@ -268,11 +276,6 @@ wc (int fd, const char *file) } bytes += bytes_read; } - if (bytes_read < 0) - { - error (0, errno, "%s", file); - exit_status = 1; - } } #if HAVE_MBRTOWC && (MB_LEN_MAX > 1) # define SUPPORT_OLD_MBRTOWC 1 @@ -291,9 +294,9 @@ wc (int fd, const char *file) this is the ISO C 99 and glibc-2.2 behaviour - or not - amended ANSI C, glibc-2.1 and Solaris 2.7 behaviour. We don't have an autoconf test for this, yet. */ - int prev = 0; /* number of bytes carried over from previous round */ + size_t prev = 0; /* number of bytes carried over from previous round */ # else - const int prev = 0; + const size_t prev = 0; # endif memset (&state, 0, sizeof (mbstate_t)); @@ -303,6 +306,12 @@ wc (int fd, const char *file) # if SUPPORT_OLD_MBRTOWC mbstate_t backup_state; # endif + if (bytes_read == SAFE_READ_ERROR) + { + error (0, errno, "%s", file); + exit_status = 1; + break; + } bytes += bytes_read; p = buf; @@ -403,11 +412,6 @@ wc (int fd, const char *file) prev = bytes_read; # endif } - if (bytes_read < 0) - { - error (0, errno, "%s", file); - exit_status = 1; - } if (linepos > linelength) linelength = linepos; if (in_word) @@ -422,6 +426,12 @@ wc (int fd, const char *file) while ((bytes_read = safe_read (fd, buf, BUFFER_SIZE)) > 0) { const char *p = buf; + if (bytes_read == SAFE_READ_ERROR) + { + error (0, errno, "%s", file); + exit_status = 1; + break; + } bytes += bytes_read; do @@ -464,11 +474,6 @@ wc (int fd, const char *file) } while (--bytes_read); } - if (bytes_read < 0) - { - error (0, errno, "%s", file); - exit_status = 1; - } if (linepos > linelength) linelength = linepos; if (in_word) |