From 0af664efb9471b58244180dcbe16f5b45fd9792e Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Tue, 3 May 2016 22:12:20 +0200 Subject: make ykfde-cpio understand command parameters --- bin/Makefile | 2 +- bin/ykfde-cpio.c | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 2 deletions(-) (limited to 'bin') 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 #include +#include #include #include #include @@ -19,6 +20,17 @@ #include #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; -- cgit v1.2.3-54-g00ecf