From 12e27a1b2adf14c33694db82e1f6f8bde560b9a2 Mon Sep 17 00:00:00 2001 From: Daniel Wagner Date: Mon, 12 Jun 2017 12:50:42 +0200 Subject: jffsX-utils: Return error code if command line option is unknown 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 Signed-off-by: David Oberhollenzer --- jffsX-utils/jffs2dump.c | 8 ++++---- jffsX-utils/mkfs.jffs2.c | 4 +++- jffsX-utils/sumtool.c | 4 +++- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'jffsX-utils') diff --git a/jffsX-utils/jffs2dump.c b/jffsX-utils/jffs2dump.c index 82f3197..a7d99e8 100644 --- a/jffsX-utils/jffs2dump.c +++ b/jffsX-utils/jffs2dump.c @@ -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]; } diff --git a/jffsX-utils/mkfs.jffs2.c b/jffsX-utils/mkfs.jffs2.c index 88e6cab..2fb7730 100644 --- a/jffsX-utils/mkfs.jffs2.c +++ b/jffsX-utils/mkfs.jffs2.c @@ -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; diff --git a/jffsX-utils/sumtool.c b/jffsX-utils/sumtool.c index 0958615..a995bdf 100644 --- a/jffsX-utils/sumtool.c +++ b/jffsX-utils/sumtool.c @@ -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; -- cgit v1.2.3