diff options
author | Jim Meyering <jim@meyering.net> | 2003-07-20 15:45:29 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-07-20 15:45:29 +0000 |
commit | 224d5c81705cdf1cfc3add6a3fa14eb90fc3ed07 (patch) | |
tree | ce5ab857d4f9143869d4100367fa002eaf332a1b | |
parent | 47c0b910f1813f8dd1792ea113fd814e1f274293 (diff) | |
download | coreutils-224d5c81705cdf1cfc3add6a3fa14eb90fc3ed07.tar.xz |
(write_counts): Add a comment.
(wc): Rename `file' parameter.
Set new local, `file', to be the file name, or (when it's NULL)
_("standard output") so that all uses of `file' use the proper value.
Use STREQ, not strcmp.
-rw-r--r-- | src/wc.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -156,6 +156,8 @@ read standard input.\n\ exit (status == 0 ? EXIT_SUCCESS : EXIT_FAILURE); } +/* FILE is the name of the file (or NULL for standard input) + associated with the specified counters. */ static void write_counts (uintmax_t lines, uintmax_t words, @@ -197,13 +199,16 @@ write_counts (uintmax_t lines, putchar ('\n'); } +/* FILE_X is the name of the file (or NULL for standard input) that is + open on descriptor FD. */ static void -wc (int fd, char const *file, struct fstatus *fstatus) +wc (int fd, char const *file_x, struct fstatus *fstatus) { char buf[BUFFER_SIZE + 1]; size_t bytes_read; uintmax_t lines, words, chars, bytes, linelength; int count_bytes, count_chars, count_complicated; + char const *file = file_x == NULL ? _("standard input") : file; lines = words = chars = bytes = linelength = 0; @@ -257,7 +262,7 @@ wc (int fd, char const *file, struct fstatus *fstatus) { if (bytes_read == SAFE_READ_ERROR) { - error (0, errno, "%s", file ? file : _("standard input")); + error (0, errno, "%s", file); exit_status = 1; break; } @@ -275,7 +280,7 @@ wc (int fd, char const *file, struct fstatus *fstatus) if (bytes_read == SAFE_READ_ERROR) { - error (0, errno, "%s", file ? file : _("standard input")); + error (0, errno, "%s", file); exit_status = 1; break; } @@ -494,7 +499,7 @@ wc (int fd, char const *file, struct fstatus *fstatus) if (count_chars < print_chars) chars = bytes; - write_counts (lines, words, chars, bytes, linelength, file); + write_counts (lines, words, chars, bytes, linelength, file_x); total_lines += lines; total_words += words; total_chars += chars; @@ -549,9 +554,9 @@ get_input_fstatus (int nfiles, char * const *file) int i; for (i = 0; i < nfiles; i++) - fstatus[i].failed = (file[i] && strcmp (file[i], "-") != 0 - ? stat (file[i], &fstatus[i].st) - : fstat (STDIN_FILENO, &fstatus[i].st)); + fstatus[i].failed = (file[i] && STREQ (file[i], "-") + ? fstat (STDIN_FILENO, &fstatus[i].st) + : stat (file[i], &fstatus[i].st)); } return fstatus; |