From da5dc507512d75c38f41f16b51841c32cb6a04e6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 11 Apr 2005 20:11:27 +0000 Subject: [PATCH] (bsd_sum_file, sysv_sym_file): Use same pattern as elsewhere for checking for stdin. --- src/sum.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/sum.c b/src/sum.c index 317064e20..e39d7ad3c 100644 --- a/src/sum.c +++ b/src/sum.c @@ -91,8 +91,9 @@ bsd_sum_file (const char *file, int print_name) 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; @@ -120,12 +121,12 @@ bsd_sum_file (const char *file, int print_name) 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; @@ -158,9 +159,11 @@ sysv_sum_file (const char *file, int print_name) /* 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 @@ -186,7 +189,7 @@ sysv_sum_file (const char *file, int print_name) if (bytes_read == SAFE_READ_ERROR) { error (0, errno, "%s", file); - if (!STREQ (file, "-")) + if (!is_stdin) close (fd); return false; } @@ -196,7 +199,7 @@ sysv_sum_file (const char *file, int print_name) total_bytes += bytes_read; } - if (!STREQ (file, "-") && close (fd) == -1) + if (!is_stdin && close (fd) != 0) { error (0, errno, "%s", file); return false; -- 2.34.1