summaryrefslogtreecommitdiff
path: root/nandtest.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 /nandtest.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 'nandtest.c')
-rw-r--r--nandtest.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/nandtest.c b/nandtest.c
index 3437b57..1876bb2 100644
--- a/nandtest.c
+++ b/nandtest.c
@@ -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) {