From 7dd42c510dc8ab10f52dcc2d20dc8af412be0744 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Tue, 19 Jul 2016 15:06:58 +0200 Subject: Unify version string printing When a program does sophisticated enough command line processing (i.e. getopt), make sure it responds to -V and --version. When a program prints a version string, make sure it uses the common_print_version macro to print out its name, that it is part of mtd-utils and the mtd-utils version from the build system in a fashion similar to common program packages like the GNU coreutils. When a program responds to -V/--version or -h/--help, make sure it reports success exit status. Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger --- nand-utils/nandtest.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'nand-utils/nandtest.c') diff --git a/nand-utils/nandtest.c b/nand-utils/nandtest.c index 2ef7cc8..5676733 100644 --- a/nand-utils/nandtest.c +++ b/nand-utils/nandtest.c @@ -22,6 +22,7 @@ void usage(int status) fprintf(status ? stderr : stdout, "usage: %s [OPTIONS] \n\n" " -h, --help Display this help output\n" + " -V, --version Display version information and exit\n" " -m, --markbad Mark blocks bad if they appear so\n" " -s, --seed Supply random seed\n" " -p, --passes Number of passes\n" @@ -160,9 +161,10 @@ int main(int argc, char **argv) seed = time(NULL); for (;;) { - static const char short_options[] = "hkl:mo:p:r:s:"; + static const char short_options[] = "hkl:mo:p:r:s:V"; static const struct option long_options[] = { { "help", no_argument, 0, 'h' }, + { "version", no_argument, 0, 'V' }, { "markbad", no_argument, 0, 'm' }, { "seed", required_argument, 0, 's' }, { "passes", required_argument, 0, 'p' }, @@ -181,7 +183,10 @@ int main(int argc, char **argv) case 'h': usage(0); break; - + case 'V': + common_print_version(); + exit(EXIT_SUCCESS); + break; case '?': usage(1); break; -- cgit v1.2.3