summaryrefslogtreecommitdiffstats
path: root/misc-utils/uuidgen.c
diff options
context:
space:
mode:
authorKarel Zak2009-05-21 16:02:42 +0200
committerKarel Zak2009-05-22 10:06:16 +0200
commit0140c3972bd68ccfe3a418a0c5c5b4117d6e931c (patch)
treeffbdd70a85ff450b01c321905a1929b4985c5ffc /misc-utils/uuidgen.c
parentbuild-sys: add --disable-tls (diff)
downloadkernel-qcow2-util-linux-0140c3972bd68ccfe3a418a0c5c5b4117d6e931c.tar.gz
kernel-qcow2-util-linux-0140c3972bd68ccfe3a418a0c5c5b4117d6e931c.tar.xz
kernel-qcow2-util-linux-0140c3972bd68ccfe3a418a0c5c5b4117d6e931c.zip
uuidgen: new command (from e2fsprogs)
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'misc-utils/uuidgen.c')
-rw-r--r--misc-utils/uuidgen.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
new file mode 100644
index 000000000..3cf6ec915
--- /dev/null
+++ b/misc-utils/uuidgen.c
@@ -0,0 +1,77 @@
+/*
+ * gen_uuid.c --- generate a DCE-compatible uuid
+ *
+ * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
+ *
+ * %Begin-Header%
+ * This file may be redistributed under the terms of the GNU Public
+ * License.
+ * %End-Header%
+ */
+
+#include <stdio.h>
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#else
+extern int getopt(int argc, char * const argv[], const char *optstring);
+extern char *optarg;
+extern int optind;
+#endif
+
+#include "uuid.h"
+#include "nls.h"
+
+#define DO_TYPE_TIME 1
+#define DO_TYPE_RANDOM 2
+
+static void usage(const char *progname)
+{
+ fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
+ exit(1);
+}
+
+int
+main (int argc, char *argv[])
+{
+ int c;
+ int do_type = 0;
+ char str[37];
+ uuid_t uu;
+
+ setlocale(LC_ALL, "");
+ bindtextdomain(PACKAGE, LOCALEDIR);
+ textdomain(PACKAGE);
+
+ while ((c = getopt (argc, argv, "tr")) != EOF)
+ switch (c) {
+ case 't':
+ do_type = DO_TYPE_TIME;
+ break;
+ case 'r':
+ do_type = DO_TYPE_RANDOM;
+ break;
+ default:
+ usage(argv[0]);
+ }
+
+ switch (do_type) {
+ case DO_TYPE_TIME:
+ uuid_generate_time(uu);
+ break;
+ case DO_TYPE_RANDOM:
+ uuid_generate_random(uu);
+ break;
+ default:
+ uuid_generate(uu);
+ break;
+ }
+
+ uuid_unparse(uu, str);
+
+ printf("%s\n", str);
+
+ return 0;
+}