aboutsummaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rw-r--r--bin/Makefile2
-rw-r--r--bin/ykfde-cpio.c35
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;