Fix the pwd and group functions. The bb_ stuff was a leftover from
[oweals/busybox.git] / wc.c
diff --git a/wc.c b/wc.c
index b1c9a51cdfec21d2b57f44ee848faf4a7a215223..619c161a70f5eb93c4fe345034c31a1596370651 100644 (file)
--- a/wc.c
+++ b/wc.c
@@ -23,6 +23,7 @@
 #include "busybox.h"
 #include <stdio.h>
 #include <getopt.h>
+#include <stdlib.h>
 
 static int total_lines, total_words, total_chars, max_length;
 static int print_lines, print_words, print_chars, print_length;
@@ -105,7 +106,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;
@@ -134,14 +135,13 @@ int wc_main(int argc, char **argv)
 
        if (argv[optind] == NULL || strcmp(argv[optind], "-") == 0) {
                wc_file(stdin, "");
-               exit(TRUE);
+               return EXIT_SUCCESS;
        } else {
                while (optind < argc) {
-                       file = fopen(argv[optind], "r");
-                       if (file == NULL) {
-                               fatalError(argv[optind]);
-                       }
-                       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++;
                }
@@ -151,5 +151,5 @@ int wc_main(int argc, char **argv)
                print_counts(total_lines, total_words, total_chars,
                                         max_length, "total");
 
-       return ;
+       return status;
 }