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;
{
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)
{
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;
}
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
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));
# 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;
prev = bytes_read;
# endif
}
- if (bytes_read < 0)
- {
- error (0, errno, "%s", file);
- exit_status = 1;
- }
if (linepos > linelength)
linelength = linepos;
if (in_word)
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
}
while (--bytes_read);
}
- if (bytes_read < 0)
- {
- error (0, errno, "%s", file);
- exit_status = 1;
- }
if (linepos > linelength)
linelength = linepos;
if (in_word)