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 --- misc-utils/ftl_check.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'misc-utils/ftl_check.c') diff --git a/misc-utils/ftl_check.c b/misc-utils/ftl_check.c index 0eada8f..d7d2e8b 100644 --- a/misc-utils/ftl_check.c +++ b/misc-utils/ftl_check.c @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -175,14 +176,23 @@ void showusage(void) /*====================================================================*/ +static const struct option long_opts[] = { + {"help", no_argument, 0, 'h'}, + {"version", no_argument, 0, 'V'}, + {0, 0, 0, 0}, +}; + int main(int argc, char *argv[]) { - int optch, errflg, fd; + int c, optch, errflg, fd; struct stat buf; errflg = 0; - while ((optch = getopt(argc, argv, "h")) != -1) { + while ((optch = getopt_long(argc, argv, "hV", long_opts, &c)) != -1) { switch (optch) { + case 'V': + common_print_version(); + exit(EXIT_SUCCESS); case 'h': errflg = 1; break; default: -- cgit v1.2.3