]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/uuidgen.c
Merge branch 'PR/libmount-exec-errors' of github.com:karelzak/util-linux-work
[thirdparty/util-linux.git] / misc-utils / uuidgen.c
index ee1235d32f5adcbb6a4f7d4ea42e956f863ffef2..56dea3c711f1b99946b41d3902322623d8905ac7 100644 (file)
@@ -19,6 +19,7 @@
 #include "closestream.h"
 #include "strutils.h"
 #include "optutils.h"
+#include "xalloc.h"
 
 static void __attribute__((__noreturn__)) usage(void)
 {
@@ -34,15 +35,17 @@ static void __attribute__((__noreturn__)) usage(void)
        fputs(_(" -r, --random          generate random-based uuid\n"), out);
        fputs(_(" -t, --time            generate time-based uuid\n"), out);
        fputs(_(" -n, --namespace <ns>  generate hash-based uuid in this namespace\n"), out);
-       printf(_("                        available namespaces: %s\n"), "@dns @url @oid @x500");
+       fprintf(out, _("                        available namespaces: %s\n"), "@dns @url @oid @x500");
        fputs(_(" -N, --name <name>     generate hash-based uuid from this name\n"), out);
        fputs(_(" -m, --md5             generate md5 hash\n"), out);
        fputs(_(" -C, --count <num>     generate more uuids in loop\n"), out);
        fputs(_(" -s, --sha1            generate sha1 hash\n"), out);
+       fputs(_(" -6, --time-v6         generate time-based v6 uuid\n"), out);
+       fputs(_(" -7, --time-v7         generate time-based v7 uuid\n"), out);
        fputs(_(" -x, --hex             interpret name as hex string\n"), out);
        fputs(USAGE_SEPARATOR, out);
-       printf(USAGE_HELP_OPTIONS(21));
-       printf(USAGE_MAN_TAIL("uuidgen(1)"));
+       fprintf(out, USAGE_HELP_OPTIONS(21));
+       fprintf(out, USAGE_MAN_TAIL("uuidgen(1)"));
        exit(EXIT_SUCCESS);
 }
 
@@ -57,7 +60,7 @@ badstring:
                errtryhelp(EXIT_FAILURE);
        }
 
-       value2 = malloc(*valuelen / 2 + 1);
+       value2 = xmalloc(*valuelen / 2 + 1);
 
        for (x = n = 0; n < *valuelen; n++) {
                c = value[n];
@@ -103,14 +106,16 @@ main (int argc, char *argv[])
                {"md5", no_argument, NULL, 'm'},
                {"count", required_argument, NULL, 'C'},
                {"sha1", no_argument, NULL, 's'},
+               {"time-v6", no_argument, NULL, '6'},
+               {"time-v7", no_argument, NULL, '7'},
                {"hex", no_argument, NULL, 'x'},
                {NULL, 0, NULL, 0}
        };
 
        static const ul_excl_t excl[] = {
+               { '6', '7', 'm', 'r', 's', 't' },
                { 'C', 'm', 's' },
                { 'N', 'r', 't' },
-               { 'm', 'r', 's', 't' },
                { 'n', 'r', 't' },
                { 0 }
        };
@@ -121,7 +126,7 @@ main (int argc, char *argv[])
        textdomain(PACKAGE);
        close_stdout_atexit();
 
-       while ((c = getopt_long(argc, argv, "C:rtVhn:N:msx", longopts, NULL)) != -1) {
+       while ((c = getopt_long(argc, argv, "C:rtVhn:N:msx67", longopts, NULL)) != -1) {
 
                err_exclusive_options(c, longopts, excl, excl_st);
 
@@ -150,6 +155,12 @@ main (int argc, char *argv[])
                case 'x':
                        is_hex = 1;
                        break;
+               case '6':
+                       do_type = UUID_TYPE_DCE_TIME_V6;
+                       break;
+               case '7':
+                       do_type = UUID_TYPE_DCE_TIME_V7;
+                       break;
 
                case 'h':
                        usage();
@@ -191,6 +202,12 @@ main (int argc, char *argv[])
                case UUID_TYPE_DCE_TIME:
                        uuid_generate_time(uu);
                        break;
+               case UUID_TYPE_DCE_TIME_V6:
+                       uuid_generate_time_v6(uu);
+                       break;
+               case UUID_TYPE_DCE_TIME_V7:
+                       uuid_generate_time_v7(uu);
+                       break;
                case UUID_TYPE_DCE_RANDOM:
                        uuid_generate_random(uu);
                        break;