]> www.infradead.org Git - mtd-utils.git/commitdiff
jffsX-utils: Return error code if command line option is unknown
authorDaniel Wagner <daniel.wagner@siemens.com>
Mon, 12 Jun 2017 10:50:42 +0000 (12:50 +0200)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 14 Jun 2017 08:55:26 +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>
jffsX-utils/jffs2dump.c
jffsX-utils/mkfs.jffs2.c
jffsX-utils/sumtool.c

index 82f31970c7f50aad2b24d8f0a15c5b59dd530ba7..a7d99e877611691c1280af5e8f87bda5765922ca 100644 (file)
@@ -50,7 +50,7 @@
 long   imglen;         // length of image
 char   *data;          // image data
 
-void display_help (void)
+void display_help (int error)
 {
        printf("Usage: %s [OPTION]... INPUTFILE\n"
               "Dump the contents of a binary JFFS2 image.\n\n"
@@ -65,7 +65,7 @@ void display_help (void)
               " -o, --oobsize=LEN            size of oob data chunk in binary image (NAND only)\n"
               " -v, --verbose                verbose output\n",
               PROGRAM_NAME);
-       exit(0);
+       exit(error ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 void display_version (void)
@@ -124,7 +124,7 @@ void process_options (int argc, char *argv[])
 
                switch (c) {
                        case 'h':
-                               display_help();
+                               display_help(0);
                                break;
                        case 'V':
                                display_version();
@@ -161,7 +161,7 @@ void process_options (int argc, char *argv[])
        }
 
        if ((argc - optind) != 1 || error)
-               display_help ();
+               display_help (error);
 
        img = argv[optind];
 }
index 88e6cab42133a8cfa5a655e83251322565cfe35a..2fb77301431f82373e21cad46b36775a53ce0b5f 100644 (file)
@@ -1629,9 +1629,11 @@ int main(int argc, char **argv)
                                break;
 
                        case 'h':
-                       case '?':
                                puts(helptext);
                                exit(EXIT_SUCCESS);
+                       case '?':
+                               puts(helptext);
+                               exit(EXIT_FAILURE);
 
                        case 'v':
                                verbose = 1;
index 09586155f74cae77a7da74eeb35dab52297308d0..a995bdf21d8e5aa821d90ed5c5a5c03511110821 100644 (file)
@@ -156,9 +156,11 @@ void process_options (int argc, char **argv)
                                target_endian = __LITTLE_ENDIAN;
                                break;
                        case 'h':
-                       case '?':
                                puts(helptext);
                                exit(EXIT_SUCCESS);
+                       case '?':
+                               puts(helptext);
+                               exit(EXIT_FAILURE);
                        case 'v':
                                verbose = 1;
                                break;