summaryrefslogtreecommitdiff
path: root/nandwrite.c
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2013-05-08 19:02:03 -0400
committerArtem Bityutskiy <artem.bityutskiy@linux.intel.com>2013-07-01 09:00:32 +0300
commitf6b476ee29833e13c0285d49ebb75666176b2aa7 (patch)
tree494def6d89b38b79a975479a770c6a2eda30eb9b /nandwrite.c
parent450e9cb17d3d86e3e45fd427c85644ac64ec60a4 (diff)
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 <vapier@gentoo.org> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Diffstat (limited to 'nandwrite.c')
-rw-r--r--nandwrite.c26
1 files changed, 13 insertions, 13 deletions
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 <libmtd.h>
-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];