2 * gen_uuid.c --- generate a DCE-compatible uuid
4 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
7 * This file may be redistributed under the terms of the GNU Public
19 extern int getopt(int argc
, char * const argv
[], const char *optstring
);
27 #include "closestream.h"
29 #define DO_TYPE_TIME 1
30 #define DO_TYPE_RANDOM 2
32 static void __attribute__ ((__noreturn__
)) usage(FILE * out
)
34 fputs(_("\nUsage:\n"), out
);
36 _(" %s [options]\n"), program_invocation_short_name
);
38 fputs(_("\nOptions:\n"), out
);
39 fputs(_(" -r, --random generate random-based uuid\n"
40 " -t, --time generate time-based uuid\n"
41 " -V, --version output version information and exit\n"
42 " -h, --help display this help and exit\n\n"), out
);
44 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
48 main (int argc
, char *argv
[])
55 static const struct option longopts
[] = {
56 {"random", no_argument
, NULL
, 'r'},
57 {"time", no_argument
, NULL
, 't'},
58 {"version", no_argument
, NULL
, 'V'},
59 {"help", no_argument
, NULL
, 'h'},
63 setlocale(LC_ALL
, "");
64 bindtextdomain(PACKAGE
, LOCALEDIR
);
68 while ((c
= getopt_long(argc
, argv
, "rtVh", longopts
, NULL
)) != -1)
71 do_type
= DO_TYPE_TIME
;
74 do_type
= DO_TYPE_RANDOM
;
77 printf(UTIL_LINUX_VERSION
);
87 uuid_generate_time(uu
);
90 uuid_generate_random(uu
);
97 uuid_unparse(uu
, str
);