uintmax_t total_bytes = 0; /* The number of bytes. */
int ch; /* Each character read. */
char hbuf[LONGEST_HUMAN_READABLE + 1];
+ bool is_stdin = STREQ (file, "-");
- if (STREQ (file, "-"))
+ if (is_stdin)
{
fp = stdin;
have_read_stdin = true;
if (ferror (fp))
{
error (0, errno, "%s", file);
- if (!STREQ (file, "-"))
+ if (!is_stdin)
fclose (fp);
return false;
}
- if (!STREQ (file, "-") && fclose (fp) == EOF)
+ if (!is_stdin && fclose (fp) != 0)
{
error (0, errno, "%s", file);
return false;
/* The sum of all the input bytes, modulo (UINT_MAX + 1). */
unsigned int s = 0;
- if (STREQ (file, "-"))
+ bool is_stdin = STREQ (file, "-");
+
+ if (is_stdin)
{
- fd = 0;
+ fd = STDIN_FILENO;
have_read_stdin = true;
}
else
if (bytes_read == SAFE_READ_ERROR)
{
error (0, errno, "%s", file);
- if (!STREQ (file, "-"))
+ if (!is_stdin)
close (fd);
return false;
}
total_bytes += bytes_read;
}
- if (!STREQ (file, "-") && close (fd) == -1)
+ if (!is_stdin && close (fd) != 0)
{
error (0, errno, "%s", file);
return false;