aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coreutils/wc.c10
-rw-r--r--utility.c2
-rw-r--r--wc.c10
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}
diff --git a/utility.c b/utility.c
index 9a303751d..11ade982b 100644
--- a/utility.c
+++ b/utility.c
@@ -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
1725FILE *wfopen(const char *path, const char *mode) 1725FILE *wfopen(const char *path, const char *mode)
1726{ 1726{
1727 FILE *fp; 1727 FILE *fp;
diff --git a/wc.c b/wc.c
index 9d569459d..e6f753435 100644
--- a/wc.c
+++ b/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}