]> www.infradead.org Git - mtd-utils.git/commitdiff
nor-utils: Return error code if command line option is unknown
authorDaniel Wagner <daniel.wagner@siemens.com>
Mon, 12 Jun 2017 10:50:52 +0000 (12:50 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 14 Jun 2017 08:55:27 +0000 (10:55 +0200)
The tools in question will quit with an exit code 0 if the command
line option was not recognized. By returning an error code a calling
script has the possibility to distinguish between a real success and
an invalid invocation.

Signed-off-by: Daniel Wagner <daniel.wagner@siemens.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
nor-utils/rfddump.c
nor-utils/rfdformat.c

index 048f58ca4ec932040995931bc4cb26ae4cb28c85..5141ea37b9263fc46a6f99d94e790acd85f1cbb3 100644 (file)
@@ -55,7 +55,7 @@ struct rfd {
        int verbose;
 };
 
-void display_help(void)
+void display_help(int status)
 {
        printf("Usage: %s [OPTIONS] MTD-device filename\n"
                        "Dumps the contents of a resident flash disk\n"
@@ -65,7 +65,7 @@ void display_help(void)
                        "-v         --verbose           Be verbose\n"
                        "-b size    --blocksize          Block size (defaults to erase unit)\n",
                        PROGRAM_NAME);
-       exit(0);
+       exit(status);
 }
 
 void display_version(void)
@@ -101,7 +101,7 @@ void process_options(int argc, char *argv[], struct rfd *rfd)
 
                switch (c) {
                        case 'h':
-                               display_help();
+                               display_help(EXIT_SUCCESS);
                                break;
                        case 'V':
                                display_version();
@@ -119,7 +119,7 @@ void process_options(int argc, char *argv[], struct rfd *rfd)
        }
 
        if ((argc - optind) != 2 || error)
-               display_help();
+               display_help(EXIT_FAILURE);
 
        rfd->mtd_filename = argv[optind];
        rfd->out_filename = argv[optind + 1];
index d393975e235454321b1f44004c330f5ba5b54a07..1f01a8531012138b1b47ddccec32035f6dd918f2 100644 (file)
@@ -30,7 +30,7 @@
 
 #include "common.h"
 
-void display_help(void)
+void display_help(int status)
 {
        printf("Usage: %s [OPTIONS] MTD-device\n"
                        "Formats NOR flash for resident flash disk\n"
@@ -38,7 +38,7 @@ void display_help(void)
                        "-h         --help               display this help and exit\n"
                        "-V         --version            output version information and exit\n",
                        PROGRAM_NAME);
-       exit(0);
+       exit(status);
 }
 
 void display_version(void)
@@ -69,7 +69,7 @@ void process_options(int argc, char *argv[], const char **mtd_filename)
 
                switch (c) {
                        case 'h':
-                               display_help();
+                               display_help(EXIT_SUCCESS);
                                break;
                        case 'V':
                                display_version();
@@ -81,7 +81,7 @@ void process_options(int argc, char *argv[], const char **mtd_filename)
        }
 
        if ((argc - optind) != 1 || error)
-               display_help();
+               display_help(EXIT_FAILURE);
 
        *mtd_filename = argv[optind];
 }