diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-10-09 18:21:44 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-10-09 18:21:44 +0000 |
commit | 214c42b6ebfbb7faf7506decc3faf31b1f95d558 (patch) | |
tree | e307b6cec6e7143fd03604aa03384001751ddb33 | |
parent | c4b83c9f4c07f6f03ec41ad353dd6d0f4718c8aa (diff) | |
download | busybox-w32-214c42b6ebfbb7faf7506decc3faf31b1f95d558.tar.gz busybox-w32-214c42b6ebfbb7faf7506decc3faf31b1f95d558.tar.bz2 busybox-w32-214c42b6ebfbb7faf7506decc3faf31b1f95d558.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
git-svn-id: svn://busybox.net/trunk/busybox@1174 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r-- | coreutils/wc.c | 10 | ||||
-rw-r--r-- | utility.c | 2 | ||||
-rw-r--r-- | wc.c | 10 |
3 files changed, 13 insertions, 9 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 | } |
@@ -1721,7 +1721,7 @@ void xregcomp(regex_t *preg, const char *regex, int cflags) | |||
1721 | } | 1721 | } |
1722 | #endif | 1722 | #endif |
1723 | 1723 | ||
1724 | #if defined BB_CAT || defined BB_HEAD | 1724 | #if defined BB_CAT || defined BB_HEAD || defined BB_WC |
1725 | FILE *wfopen(const char *path, const char *mode) | 1725 | FILE *wfopen(const char *path, const char *mode) |
1726 | { | 1726 | { |
1727 | FILE *fp; | 1727 | FILE *fp; |
@@ -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 | } |