diff options
author | Li Guifu <blucerlee@gmail.com> | 2019-10-22 12:10:09 +0800 |
---|---|---|
committer | Gao Xiang <hsiangkao@aol.com> | 2019-10-23 01:27:15 +0800 |
commit | 3bf2358c3a31736abf181ade4fa9114201041dd7 (patch) | |
tree | 6bb6f6d07087f47e54416465afc1b6d61792ae55 | |
parent | 116ac0a254fcda1282b47b5cfd97c549c77b613f (diff) |
erofs-utils: introduce long parameter option
Only long option "--help" is valid now.
Link: https://lore.kernel.org/r/20191022172518.9020-1-hsiangkao@aol.com
Signed-off-by: Li Guifu <blucerlee@gmail.com>
Tested-by: Li Guifu <blucerlee@gmail.com>
Signed-off-by: Gao Xiang <hsiangkao@aol.com>
-rw-r--r-- | configure.ac | 1 | ||||
-rw-r--r-- | mkfs/main.c | 14 |
2 files changed, 14 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 8c31cb7..4f88678 100644 --- a/configure.ac +++ b/configure.ac @@ -71,6 +71,7 @@ AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4]) AC_CHECK_HEADERS(m4_flatten([ dirent.h fcntl.h + getopt.h inttypes.h linux/falloc.h linux/fs.h diff --git a/mkfs/main.c b/mkfs/main.c index 71c81f5..31cf1c2 100644 --- a/mkfs/main.c +++ b/mkfs/main.c @@ -13,6 +13,7 @@ #include <limits.h> #include <libgen.h> #include <sys/stat.h> +#include <getopt.h> #include "erofs/config.h" #include "erofs/print.h" #include "erofs/cache.h" @@ -23,6 +24,11 @@ #define EROFS_SUPER_END (EROFS_SUPER_OFFSET + sizeof(struct erofs_super_block)) +static struct option long_options[] = { + {"help", no_argument, 0, 1}, + {0, 0, 0, 0}, +}; + static void usage(void) { fprintf(stderr, "usage: [options] FILE DIRECTORY\n\n"); @@ -32,6 +38,7 @@ static void usage(void) fprintf(stderr, " -x# set xattr tolerance to # (< 0, disable xattrs; default 2)\n"); fprintf(stderr, " -EX[,...] X=extended options\n"); fprintf(stderr, " -T# set a fixed UNIX timestamp # to all files\n"); + fprintf(stderr, " --help display this help and exit\n"); } static int parse_extended_opts(const char *opts) @@ -96,7 +103,8 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) char *endptr; int opt, i; - while ((opt = getopt(argc, argv, "d:x:z:E:T:")) != -1) { + while((opt = getopt_long(argc, argv, "d:x:z:E:T:", + long_options, NULL)) != -1) { switch (opt) { case 'z': if (!optarg) { @@ -146,6 +154,10 @@ static int mkfs_parse_options_cfg(int argc, char *argv[]) } break; + case 1: + usage(); + exit(0); + default: /* '?' */ return -EINVAL; } |