[PATCH v0 12/20] nor-utils: rfdformat: Return error code if command line option is unknown

Daniel Wagner daniel.wagner at siemens.com
Mon Jun 12 03:50:53 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>
---
 nor-utils/rfdformat.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/nor-utils/rfdformat.c b/nor-utils/rfdformat.c
index d393975e2354..1f01a8531012 100644
--- a/nor-utils/rfdformat.c
+++ b/nor-utils/rfdformat.c
@@ -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];
 }
-- 
2.9.4




More information about the linux-mtd mailing list