summaryrefslogtreecommitdiff
path: root/usr/src/cmd/uuidgen
diff options
context:
space:
mode:
authorAlexander Eremin <a.eremin@nexenta.com>2015-09-19 02:58:22 -0700
committerRichard Lowe <richlowe@richlowe.net>2015-09-20 18:09:38 -0400
commit71d45228ba245d505c3beae1d756e775616f6d5a (patch)
treecfc8108d2f94de691a8dde2937e7a8da2bc0902e /usr/src/cmd/uuidgen
parentfca4268092e9961ebb9b5e0098dcebc545023586 (diff)
downloadillumos-joyent-71d45228ba245d505c3beae1d756e775616f6d5a.tar.gz
4769 Want implementation of uuid command
Reviewed by: Andy Stormont <astormont@racktopsystems.com> Reviewed by: Gordon Ross <gordon.ross@nexenta.com> Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com> Approved by: Richard Lowe <richlowe@richlowe.net>
Diffstat (limited to 'usr/src/cmd/uuidgen')
-rw-r--r--usr/src/cmd/uuidgen/Makefile35
-rw-r--r--usr/src/cmd/uuidgen/uuidgen.c102
2 files changed, 137 insertions, 0 deletions
diff --git a/usr/src/cmd/uuidgen/Makefile b/usr/src/cmd/uuidgen/Makefile
new file mode 100644
index 0000000000..663e2dbd43
--- /dev/null
+++ b/usr/src/cmd/uuidgen/Makefile
@@ -0,0 +1,35 @@
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+#
+
+PROG= uuidgen
+
+include ../Makefile.cmd
+
+CFLAGS += $(CCVERBOSE)
+LDLIBS += -luuid
+
+C99MODE = $(C99_ENABLE)
+
+.KEEP_STATE:
+
+all: $(PROG)
+
+install: all $(ROOTPROG)
+
+clean:
+
+lint: lint_PROG
+
+include ../Makefile.targ
diff --git a/usr/src/cmd/uuidgen/uuidgen.c b/usr/src/cmd/uuidgen/uuidgen.c
new file mode 100644
index 0000000000..eb7794650d
--- /dev/null
+++ b/usr/src/cmd/uuidgen/uuidgen.c
@@ -0,0 +1,102 @@
+/*
+ * This file and its contents are supplied under the terms of the
+ * Common Development and Distribution License ("CDDL"), version 1.0.
+ * You may only use this file in accordance with the terms of version
+ * 1.0 of the CDDL.
+ *
+ * A full copy of the text of the CDDL should have accompanied this
+ * source. A copy of the CDDL is also available via the Internet at
+ * http://www.illumos.org/license/CDDL.
+ */
+
+/*
+ * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libgen.h>
+#include <uuid/uuid.h>
+#include <getopt.h>
+#include <locale.h>
+
+static char *progname;
+static int rflag, tflag;
+static char uu_string[UUID_PRINTABLE_STRING_LENGTH];
+
+static void
+usage(void)
+{
+ (void) fprintf(stderr, gettext(
+ "Usage: %s [-r | -t] [-o filename]\n"), progname);
+ exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+ FILE *out;
+ uuid_t uu = { 0 };
+ int c;
+
+ (void) setlocale(LC_ALL, "");
+
+#if !defined(TEXT_DOMAIN)
+#define TEXT_DOMAIN "SYS_TEST"
+#endif
+ (void) textdomain(TEXT_DOMAIN);
+
+ progname = basename(argv[0]);
+ out = stdout;
+ while ((c = getopt(argc, argv, ":rto:")) != EOF) {
+ switch ((char)c) {
+ case 'r':
+ rflag++;
+ break;
+ case 't':
+ tflag++;
+ break;
+ case 'o':
+ if ((out = fopen(optarg, "w")) == NULL) {
+ (void) fprintf(stderr, gettext(
+ "%s: cannot open %s\n"),
+ progname, optarg);
+ return (1);
+ }
+ break;
+ case '?': /* fallthrough */
+ default:
+ usage();
+ }
+ }
+
+ if ((rflag && tflag) || optind != argc) {
+ usage();
+ }
+
+ if (rflag) {
+ /* DCE version 4 */
+ uuid_generate_random(uu);
+ } else if (tflag) {
+ /* DCE version 1 */
+ uuid_generate_time(uu);
+ } else {
+ uuid_generate(uu);
+ }
+
+ if (uuid_is_null(uu) != 0) {
+ (void) fprintf(stderr, gettext(
+ "%s: failed to "
+ "generate uuid\n"), progname);
+ exit(1);
+ }
+
+ uuid_unparse(uu, uu_string);
+
+ (void) fprintf(out, "%s\n", uu_string);
+
+ if (out != NULL && out != stdout)
+ (void) fclose(out);
+
+ return (0);
+}