Add errno.h
[oweals/busybox.git] / wc.c
diff --git a/wc.c b/wc.c
index 02e2b2aa661b99b81f4ca33fab0d61b49ffe2939..e6f753435610fa68bcd92a622c82bd8fbab83f32 100644 (file)
--- a/wc.c
+++ b/wc.c
@@ -2,7 +2,7 @@
 /*
  * Mini wc implementation for busybox
  *
- * by Edward Betts <edward@debian.org>
+ * Copyright (C) 2000  Edward Betts <edward@debian.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@
  *
  */
 
-#include "internal.h"
+#include "busybox.h"
 #include <stdio.h>
 #include <getopt.h>
 
@@ -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;
@@ -134,14 +134,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 +150,5 @@ int wc_main(int argc, char **argv)
                print_counts(total_lines, total_words, total_chars,
                                         max_length, "total");
 
-       return ;
+       return status;
 }