[PATCH v0 01/20] jffs2dump: Return error code if command line option is unknown

Daniel Wagner daniel.wagner at siemens.com
Mon Jun 12 03:50:42 PDT 2017


The tool 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 at siemens.com>
---
 jffsX-utils/jffs2dump.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/jffsX-utils/jffs2dump.c b/jffsX-utils/jffs2dump.c
index a8d082bf1e39..df5b1e120b69 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(EXIT_SUCCESS);
 				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];
 }
-- 
2.9.4




More information about the linux-mtd mailing list