cksum, printenv: report errors via exitcode
authorDenis Vlasenko <vda.linux@googlemail.com>
Tue, 11 Nov 2008 22:59:41 +0000 (22:59 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Tue, 11 Nov 2008 22:59:41 +0000 (22:59 -0000)
function                                             old     new   delta
cksum_main                                           296     315     +19
printenv_main                                         74      86     +12

coreutils/cksum.c
coreutils/printenv.c

index 546532c3c21d4618ed11ee72a1abbece89c3dfd4..3a77c753acf813d126a90847c1f903ed8e176228 100644 (file)
@@ -15,6 +15,7 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
        uint32_t crc;
        off_t length, filesize;
        int bytes_read;
+       int exit_code = EXIT_SUCCESS;
        uint8_t *cp;
 
 #if ENABLE_DESKTOP
@@ -27,8 +28,10 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
        do {
                int fd = open_or_warn_stdin(*argv ? *argv : bb_msg_standard_input);
 
-               if (fd < 0)
+               if (fd < 0) {
+                       exit_code = EXIT_FAILURE;
                        continue;
+               }
                crc = 0;
                length = 0;
 
@@ -60,5 +63,5 @@ int cksum_main(int argc UNUSED_PARAM, char **argv)
                                crc, filesize, *argv);
        } while (*argv && *++argv);
 
-       fflush_stdout_and_exit(EXIT_SUCCESS);
+       fflush_stdout_and_exit(exit_code);
 }
index 6971f7258eab84d1f006b4cae17f1e34070a492e..2430f3a1aeca1d33617a29078d943270e9fdea00 100644 (file)
@@ -13,6 +13,8 @@
 int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int printenv_main(int argc UNUSED_PARAM, char **argv)
 {
+       int exit_code = EXIT_SUCCESS;
+
        /* no variables specified, show whole env */
        if (!argv[1]) {
                int e = 0;
@@ -26,8 +28,10 @@ int printenv_main(int argc UNUSED_PARAM, char **argv)
                        env = getenv(arg);
                        if (env)
                                puts(env);
+                       else
+                               exit_code = EXIT_FAILURE;
                }
        }
 
-       fflush_stdout_and_exit(EXIT_SUCCESS);
+       fflush_stdout_and_exit(exit_code);
 }