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 --- nandtest.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'nandtest.c') diff --git a/nandtest.c b/nandtest.c index 3437b57..1876bb2 100644 --- a/nandtest.c +++ b/nandtest.c @@ -16,9 +16,10 @@ #include #include "mtd/mtd-user.h" -void usage(void) +void usage(int status) { - fprintf(stderr, "usage: %s [OPTIONS] \n\n" + fprintf(status ? stderr : stdout, + "usage: %s [OPTIONS] \n\n" " -h, --help Display this help output\n" " -m, --markbad Mark blocks bad if they appear so\n" " -s, --seed Supply random seed\n" @@ -27,7 +28,7 @@ void usage(void) " -l, --length Length of flash to test\n" " -k, --keep Restore existing contents after test\n", PROGRAM_NAME); - exit(1); + exit(status); } struct mtd_info_user meminfo; @@ -142,7 +143,7 @@ int main(int argc, char **argv) seed = time(NULL); for (;;) { - static const char *short_options="hkl:mo:p:s:"; + static const char short_options[] = "hkl:mo:p:s:"; static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "markbad", no_argument, 0, 'm' }, @@ -160,8 +161,11 @@ int main(int argc, char **argv) switch (c) { case 'h': + usage(0); + break; + case '?': - usage(); + usage(1); break; case 'm': @@ -191,7 +195,7 @@ int main(int argc, char **argv) } } if (argc - optind != 1) - usage(); + usage(1); fd = open(argv[optind], O_RDWR); if (fd < 0) { -- cgit v1.2.3