aboutsummaryrefslogtreecommitdiffstats
path: root/bin/ykfde-cpio.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2016-05-03 22:12:20 +0200
committerGravatar Christian Hesse <mail@eworm.de>2016-05-03 22:12:20 +0200
commit0af664efb9471b58244180dcbe16f5b45fd9792e (patch)
tree37770e6061361caa42ccaace5f88859431d80322 /bin/ykfde-cpio.c
parentd59cb5f1999d2ea538b472fdb40dad92b0b36f74 (diff)
downloadmkinitcpio-ykfde-0af664efb9471b58244180dcbe16f5b45fd9792e.tar.gz
mkinitcpio-ykfde-0af664efb9471b58244180dcbe16f5b45fd9792e.tar.zst
make ykfde-cpio understand command parameters
Diffstat (limited to 'bin/ykfde-cpio.c')
-rw-r--r--bin/ykfde-cpio.c35
1 files changed, 34 insertions, 1 deletions
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;