diff options
author | Christian Hesse <mail@eworm.de> | 2016-05-03 22:12:20 +0200 |
---|---|---|
committer | Christian Hesse <mail@eworm.de> | 2016-05-03 22:12:20 +0200 |
commit | 0af664efb9471b58244180dcbe16f5b45fd9792e (patch) | |
tree | 37770e6061361caa42ccaace5f88859431d80322 | |
parent | d59cb5f1999d2ea538b472fdb40dad92b0b36f74 (diff) | |
download | mkinitcpio-ykfde-0af664efb9471b58244180dcbe16f5b45fd9792e.tar.gz mkinitcpio-ykfde-0af664efb9471b58244180dcbe16f5b45fd9792e.tar.zst |
make ykfde-cpio understand command parameters
-rw-r--r-- | bin/Makefile | 2 | ||||
-rw-r--r-- | bin/ykfde-cpio.c | 35 |
2 files changed, 35 insertions, 2 deletions
diff --git a/bin/Makefile b/bin/Makefile index a34dec1..8cfb3a5 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -11,7 +11,7 @@ all: ykfde ykfde-cpio ykfde: ykfde.c ../config.h ../version.h $(CC) $(CFLAGS) -lcryptsetup -liniparser -lkeyutils -lykpers-1 -lyubikey $(LDFLAGS) -o ykfde ykfde.c -ykfde-cpio: ykfde-cpio.c ../config.h +ykfde-cpio: ykfde-cpio.c ../config.h ../version.h $(CC) $(CFLAGS) -larchive $(LDFLAGS) -o ykfde-cpio ykfde-cpio.c install: ykfde ykfde-cpio diff --git a/bin/ykfde-cpio.c b/bin/ykfde-cpio.c index 26f7c99..48a8278 100644 --- a/bin/ykfde-cpio.c +++ b/bin/ykfde-cpio.c @@ -10,6 +10,7 @@ #include <dirent.h> #include <fcntl.h> +#include <getopt.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -19,6 +20,17 @@ #include <archive_entry.h> #include "../config.h" +#include "../version.h" + +#define PROGNAME "ykfde-cpio" + +const static char optstring[] = "hV"; +const static struct option options_long[] = { + /* name has_arg flag val */ + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'V' }, + { 0, 0, 0, 0 } +}; int add_dir(struct archive *archive, const char * path) { struct stat st; @@ -53,7 +65,9 @@ out: return rc; } -int main(int argc, const char **argv) { +int main(int argc, char **argv) { + int i; + unsigned int version = 0, help = 0; char cpiotmpfile[] = CPIOTMPFILE; struct archive *archive; struct archive_entry *entry; @@ -66,6 +80,25 @@ int main(int argc, const char **argv) { off_t pathlength = 0; int8_t rc = EXIT_FAILURE; + /* get command line options */ + while ((i = getopt_long(argc, argv, optstring, options_long, NULL)) != -1) + switch (i) { + case 'h': + help++; + break; + case 'V': + version++; + break; + } + + if (version > 0) + printf("%s: %s v%s (compiled: " __DATE__ ", " __TIME__ ")\n", argv[0], PROGNAME, VERSION); + + if (help > 0) + fprintf(stderr, "usage: %s [-h] [-V]\n", argv[0]); + + if (version > 0 || help > 0) + return EXIT_SUCCESS; if ((rc = fdarchive = mkstemp(cpiotmpfile)) < 0) { perror("mkstemp() failed"); goto out10; |