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
);
28 #define DO_TYPE_TIME 1
29 #define DO_TYPE_RANDOM 2
31 static void __attribute__ ((__noreturn__
)) usage(FILE * out
)
33 fprintf(out
, _("Usage: %s [options]\n"),
34 program_invocation_short_name
);
36 fprintf(out
, _("\nOptions:\n"
37 " -r, --random generate random-based uuid\n"
38 " -t, --time generate time-based uuid\n"
39 " -V, --version output version information and exit\n"
40 " -h, --help display this help and exit\n\n"));
42 exit(out
== stderr
? EXIT_FAILURE
: EXIT_SUCCESS
);
46 main (int argc
, char *argv
[])
53 static const struct option longopts
[] = {
54 {"random", required_argument
, NULL
, 'r'},
55 {"time", no_argument
, NULL
, 't'},
56 {"version", no_argument
, NULL
, 'V'},
57 {"help", no_argument
, NULL
, 'h'},
61 setlocale(LC_ALL
, "");
62 bindtextdomain(PACKAGE
, LOCALEDIR
);
65 while ((c
= getopt_long(argc
, argv
, "rtVh", longopts
, NULL
)) != -1)
68 do_type
= DO_TYPE_TIME
;
71 do_type
= DO_TYPE_RANDOM
;
74 printf(_("%s from %s\n"),
75 program_invocation_short_name
,
86 uuid_generate_time(uu
);
89 uuid_generate_random(uu
);
96 uuid_unparse(uu
, str
);