summaryrefslogtreecommitdiff
path: root/jffsX-utils/jffs2reader.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 /jffsX-utils/jffs2reader.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 'jffsX-utils/jffs2reader.c')
-rw-r--r--jffsX-utils/jffs2reader.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/jffsX-utils/jffs2reader.c b/jffsX-utils/jffs2reader.c
index a62da9a..09d1d89 100644
--- a/jffsX-utils/jffs2reader.c
+++ b/jffsX-utils/jffs2reader.c
@@ -71,6 +71,7 @@ BUGS:
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
+#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
@@ -79,6 +80,14 @@ BUGS:
#include "mtd/jffs2-user.h"
#include "common.h"
+static struct option long_opt[] = {
+ {"help", 0, NULL, 'h'},
+ {"version", 0, NULL, 'V'},
+ {NULL, 0, NULL, 0},
+};
+
+static const char *short_opt = "rd:f:tVh";
+
#define SCRATCH_SIZE (5*1024*1024)
/* macro to avoid "lvalue required as left operand of assignment" error */
@@ -857,7 +866,7 @@ void catfile(char *o, size_t size, char *path, char *b, size_t bsize,
int main(int argc, char **argv)
{
- int fd, opt, recurse = 0, want_ctime = 0;
+ int fd, opt, c, recurse = 0, want_ctime = 0;
struct stat st;
char *scratch, *dir = NULL, *file = NULL;
@@ -865,7 +874,7 @@ int main(int argc, char **argv)
char *buf;
- while ((opt = getopt(argc, argv, "rd:f:t")) > 0) {
+ while ((opt = getopt_long(argc, argv, short_opt, long_opt, &c)) > 0) {
switch (opt) {
case 'd':
dir = optarg;
@@ -879,11 +888,14 @@ int main(int argc, char **argv)
case 't':
want_ctime++;
break;
+ case 'V':
+ common_print_version();
+ exit(EXIT_SUCCESS);
default:
fprintf(stderr,
"Usage: %s <image> [-d|-f] < path >\n",
PROGRAM_NAME);
- exit(EXIT_FAILURE);
+ exit(opt == 'h' ? EXIT_SUCCESS : EXIT_FAILURE);
}
}