From f6b476ee29833e13c0285d49ebb75666176b2aa7 Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 8 May 2013 19:02:03 -0400 Subject: nand{dump, test, write}: clean up --help handling We should send the output to stdout when the user passes -h/--help and then exit(0), but otherwise the output should go to stderr and then exit(1). Signed-off-by: Mike Frysinger Signed-off-by: Artem Bityutskiy --- nandwrite.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'nandwrite.c') diff --git a/nandwrite.c b/nandwrite.c index a6b6581..edf9f83 100644 --- a/nandwrite.c +++ b/nandwrite.c @@ -42,9 +42,9 @@ #include "common.h" #include -static void display_help(void) +static void display_help(int status) { - printf( + fprintf(status == EXIT_SUCCESS ? stdout : stderr, "Usage: nandwrite [OPTION] MTD_DEVICE [INPUTFILE|-]\n" "Writes to the specified MTD device.\n" "\n" @@ -58,10 +58,10 @@ static void display_help(void) " -p, --pad Pad to page size\n" " -b, --blockalign=1|2|4 Set multiple of eraseblocks to align to\n" " -q, --quiet Don't display progress messages\n" -" --help Display this help and exit\n" +" -h, --help Display this help and exit\n" " --version Output version information and exit\n" ); - exit(EXIT_SUCCESS); + exit(status); } static void display_version(void) @@ -99,10 +99,10 @@ static void process_options(int argc, char * const argv[]) for (;;) { int option_index = 0; - static const char *short_options = "b:mnNoOpqs:a"; + static const char short_options[] = "hb:mnNoOpqs:a"; static const struct option long_options[] = { - {"help", no_argument, 0, 0}, {"version", no_argument, 0, 0}, + {"help", no_argument, 0, 'h'}, {"blockalign", required_argument, 0, 'b'}, {"markbad", no_argument, 0, 'm'}, {"noecc", no_argument, 0, 'n'}, @@ -124,12 +124,9 @@ static void process_options(int argc, char * const argv[]) switch (c) { case 0: switch (option_index) { - case 0: - display_help(); - break; - case 1: - display_version(); - break; + case 0: /* --version */ + display_version(); + break; } break; case 'q': @@ -163,6 +160,9 @@ static void process_options(int argc, char * const argv[]) case 'a': autoplace = true; break; + case 'h': + display_help(EXIT_SUCCESS); + break; case '?': error++; break; @@ -192,7 +192,7 @@ static void process_options(int argc, char * const argv[]) */ if (argc < 1 || argc > 2 || error) - display_help(); + display_help(EXIT_FAILURE); mtd_device = argv[0]; -- cgit v1.2.3