From 214c42b6ebfbb7faf7506decc3faf31b1f95d558 Mon Sep 17 00:00:00 2001 From: andersen Date: Mon, 9 Oct 2000 18:21:44 +0000 Subject: 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 --- wc.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'wc.c') 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) { FILE *file; unsigned int num_files_counted = 0; - int opt; + int opt, status = EXIT_SUCCESS; total_lines = total_words = total_chars = max_length = 0; print_lines = print_words = print_chars = print_length = 0; @@ -137,8 +137,10 @@ int wc_main(int argc, char **argv) return EXIT_SUCCESS; } else { while (optind < argc) { - file = xfopen(argv[optind], "r"); - wc_file(file, argv[optind]); + if ((file = wfopen(argv[optind], "r")) != NULL) + wc_file(file, argv[optind]); + else + status = EXIT_FAILURE; num_files_counted++; optind++; } @@ -148,5 +150,5 @@ int wc_main(int argc, char **argv) print_counts(total_lines, total_words, total_chars, max_length, "total"); - return EXIT_SUCCESS; + return status; } -- cgit v1.2.3-55-g6feb