aboutsummaryrefslogtreecommitdiff
path: root/wc.c
diff options
context:
space:
mode:
Diffstat (limited to 'wc.c')
-rw-r--r--wc.c10
1 files changed, 6 insertions, 4 deletions
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}