diff options
author | Eric Andersen <andersen@codepoet.org> | 2000-10-09 18:21:44 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2000-10-09 18:21:44 +0000 |
commit | 7a86e61a54f75c6c457be177fb20f6dde27c06d3 (patch) | |
tree | e307b6cec6e7143fd03604aa03384001751ddb33 /coreutils/wc.c | |
parent | 62f987e95f497a21bc1455153dd156aa12718574 (diff) | |
download | busybox-w32-7a86e61a54f75c6c457be177fb20f6dde27c06d3.tar.gz busybox-w32-7a86e61a54f75c6c457be177fb20f6dde27c06d3.tar.bz2 busybox-w32-7a86e61a54f75c6c457be177fb20f6dde27c06d3.zip |
Patch from Matt Kraai so wc will return a proper error code
when failing to open a file, and will not use file when it
didn't open the file.
-Erik
Diffstat (limited to 'coreutils/wc.c')
-rw-r--r-- | coreutils/wc.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/coreutils/wc.c b/coreutils/wc.c index 9d569459d..e6f753435 100644 --- a/coreutils/wc.c +++ b/coreutils/wc.c | |||
@@ -105,7 +105,7 @@ int wc_main(int argc, char **argv) | |||
105 | { | 105 | { |
106 | FILE *file; | 106 | FILE *file; |
107 | unsigned int num_files_counted = 0; | 107 | unsigned int num_files_counted = 0; |
108 | int opt; | 108 | int opt, status = EXIT_SUCCESS; |
109 | 109 | ||
110 | total_lines = total_words = total_chars = max_length = 0; | 110 | total_lines = total_words = total_chars = max_length = 0; |
111 | print_lines = print_words = print_chars = print_length = 0; | 111 | print_lines = print_words = print_chars = print_length = 0; |
@@ -137,8 +137,10 @@ int wc_main(int argc, char **argv) | |||
137 | return EXIT_SUCCESS; | 137 | return EXIT_SUCCESS; |
138 | } else { | 138 | } else { |
139 | while (optind < argc) { | 139 | while (optind < argc) { |
140 | file = xfopen(argv[optind], "r"); | 140 | if ((file = wfopen(argv[optind], "r")) != NULL) |
141 | wc_file(file, argv[optind]); | 141 | wc_file(file, argv[optind]); |
142 | else | ||
143 | status = EXIT_FAILURE; | ||
142 | num_files_counted++; | 144 | num_files_counted++; |
143 | optind++; | 145 | optind++; |
144 | } | 146 | } |
@@ -148,5 +150,5 @@ int wc_main(int argc, char **argv) | |||
148 | print_counts(total_lines, total_words, total_chars, | 150 | print_counts(total_lines, total_words, total_chars, |
149 | max_length, "total"); | 151 | max_length, "total"); |
150 | 152 | ||
151 | return EXIT_SUCCESS; | 153 | return status; |
152 | } | 154 | } |