summaryrefslogtreecommitdiffstats
path: root/misc-utils/uuidgen.c
diff options
context:
space:
mode:
authorSami Kerola2011-06-12 15:17:07 +0200
committerSami Kerola2011-06-25 14:28:56 +0200
commit0379a55d9f00b45db64b96787cee08d34176849e (patch)
treeef289c30ebf54dcaca0f5c6d70a2e5242e09a187 /misc-utils/uuidgen.c
parentwipefs: add version printing & compiler warning (diff)
downloadkernel-qcow2-util-linux-0379a55d9f00b45db64b96787cee08d34176849e.tar.gz
kernel-qcow2-util-linux-0379a55d9f00b45db64b96787cee08d34176849e.tar.xz
kernel-qcow2-util-linux-0379a55d9f00b45db64b96787cee08d34176849e.zip
uuidgen: add long options
Affects to help output as well. Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Diffstat (limited to 'misc-utils/uuidgen.c')
-rw-r--r--misc-utils/uuidgen.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 3cf6ec915..5faf2f047 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -23,14 +23,23 @@ extern int optind;
#include "uuid.h"
#include "nls.h"
+#include "c.h"
#define DO_TYPE_TIME 1
#define DO_TYPE_RANDOM 2
-static void usage(const char *progname)
+static void __attribute__ ((__noreturn__)) usage(FILE * out)
{
- fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
- exit(1);
+ fprintf(out, _("Usage: %s [options]\n"),
+ program_invocation_short_name);
+
+ fprintf(out, _("\nOptions:\n"
+ " -r, --random generate random-based uuid\n"
+ " -t, --time generate time-based uuid\n"
+ " -V, --version output version information and exit\n"
+ " -h, --help display this help and exit\n\n"));
+
+ exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
int
@@ -41,11 +50,19 @@ main (int argc, char *argv[])
char str[37];
uuid_t uu;
+ static const struct option longopts[] = {
+ {"random", required_argument, NULL, 'r'},
+ {"time", no_argument, NULL, 't'},
+ {"version", no_argument, NULL, 'V'},
+ {"help", no_argument, NULL, 'h'},
+ {NULL, 0, NULL, 0}
+ };
+
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
- while ((c = getopt (argc, argv, "tr")) != EOF)
+ while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
switch (c) {
case 't':
do_type = DO_TYPE_TIME;
@@ -53,8 +70,15 @@ main (int argc, char *argv[])
case 'r':
do_type = DO_TYPE_RANDOM;
break;
+ case 'V':
+ printf(_("%s from %s\n"),
+ program_invocation_short_name,
+ PACKAGE_STRING);
+ return EXIT_SUCCESS;
+ case 'h':
+ usage(stdout);
default:
- usage(argv[0]);
+ usage(stderr);
}
switch (do_type) {
@@ -73,5 +97,5 @@ main (int argc, char *argv[])
printf("%s\n", str);
- return 0;
+ return EXIT_SUCCESS;
}