aboutsummaryrefslogtreecommitdiff
path: root/misc-utils/flashcp.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-07-19 15:06:58 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2016-11-17 11:36:55 +0100
commit7dd42c510dc8ab10f52dcc2d20dc8af412be0744 (patch)
treefa45022d4754db6a72285d7e9f9284e877ce06c5 /misc-utils/flashcp.c
parent8a00021b2ab5529640e5acaca30a27cdaca04178 (diff)
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 <david.oberhollenzer@sigma-star.at> Signed-off-by: Richard Weinberger <richard@nod.at>
Diffstat (limited to 'misc-utils/flashcp.c')
-rw-r--r--misc-utils/flashcp.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/misc-utils/flashcp.c b/misc-utils/flashcp.c
index 3fddeb0..6594a45 100644
--- a/misc-utils/flashcp.c
+++ b/misc-utils/flashcp.c
@@ -43,9 +43,7 @@
#include <mtd/mtd-user.h>
#include <getopt.h>
-typedef int bool;
-#define true 1
-#define false 0
+#include "common.h"
#define EXIT_FAILURE 1
#define EXIT_SUCCESS 0
@@ -96,9 +94,11 @@ static void showusage(bool error)
"\n"
"usage: %1$s [ -v | --verbose ] <filename> <device>\n"
" %1$s -h | --help\n"
+ " %1$s -V | --version\n"
"\n"
" -h | --help Show this help message\n"
" -v | --verbose Show progress reports\n"
+ " -V | --version Show version information and exit\n"
" <filename> File which you want to copy to flash\n"
" <device> Flash device to write to (e.g. /dev/mtd0, /dev/mtd1, etc.)\n"
"\n",
@@ -182,10 +182,11 @@ int main (int argc,char *argv[])
for (;;) {
int option_index = 0;
- static const char *short_options = "hv";
+ static const char *short_options = "hvV";
static const struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"verbose", no_argument, 0, 'v'},
+ {"version", no_argument, 0, 'V'},
{0, 0, 0, 0},
};
@@ -204,6 +205,10 @@ int main (int argc,char *argv[])
flags |= FLAG_VERBOSE;
DEBUG("Got FLAG_VERBOSE\n");
break;
+ case 'V':
+ common_print_version();
+ exit(EXIT_SUCCESS);
+ break;
default:
DEBUG("Unknown parameter: %s\n",argv[option_index]);
showusage(true);