diff options
author | Mike Frysinger <vapier@gentoo.org> | 2013-05-08 19:02:03 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-07-01 09:00:32 +0300 |
commit | f6b476ee29833e13c0285d49ebb75666176b2aa7 (patch) | |
tree | 494def6d89b38b79a975479a770c6a2eda30eb9b /nandtest.c | |
parent | 450e9cb17d3d86e3e45fd427c85644ac64ec60a4 (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 'nandtest.c')
-rw-r--r-- | nandtest.c | 16 |
1 files changed, 10 insertions, 6 deletions
@@ -16,9 +16,10 @@ #include <asm/types.h> #include "mtd/mtd-user.h" -void usage(void) +void usage(int status) { - fprintf(stderr, "usage: %s [OPTIONS] <device>\n\n" + fprintf(status ? stderr : stdout, + "usage: %s [OPTIONS] <device>\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) { |