blob: b6f383750727ea7ef3cf55384e97e2bb20e3e292 [file] [log] [blame]
Theodore Ts'o5d45d801999-03-16 19:35:19 +00001/*
2 * gen_uuid.c --- generate a DCE-compatible uuid
3 *
Theodore Ts'o5dbb0721999-07-03 06:16:06 +00004 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
Theodore Ts'o5d45d801999-03-16 19:35:19 +00005 *
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
10 */
11
12#include <stdio.h>
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000013#ifdef HAVE_GETOPT_H
14#include <getopt.h>
Theodore Ts'o373b8332000-04-03 16:22:35 +000015#else
16extern char *optarg;
17extern int optind;
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000018#endif
Theodore Ts'o5d45d801999-03-16 19:35:19 +000019#include "uuid/uuid.h"
Theodore Ts'od9c56d32000-02-08 00:47:55 +000020#include "nls-enable.h"
Theodore Ts'o5d45d801999-03-16 19:35:19 +000021
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000022#define DO_TYPE_TIME 1
23#define DO_TYPE_RANDOM 2
24
25void usage(const char *progname)
26{
Theodore Ts'od9c56d32000-02-08 00:47:55 +000027 fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000028 exit(1);
29}
30
Theodore Ts'o5d45d801999-03-16 19:35:19 +000031int
32main (int argc, char *argv[])
33{
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000034 int c;
35 int do_type = 0;
36 char str[37];
37 uuid_t uu;
Theodore Ts'o5d45d801999-03-16 19:35:19 +000038
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000039 while ((c = getopt (argc, argv, "tr")) != EOF)
40 switch (c) {
41 case 't':
42 do_type = DO_TYPE_TIME;
43 break;
44 case 'r':
45 do_type = DO_TYPE_RANDOM;
46 break;
47 default:
48 usage(argv[0]);
49 }
50
51 switch (do_type) {
52 case DO_TYPE_TIME:
53 uuid_generate_time(uu);
54 break;
55 case DO_TYPE_RANDOM:
56 uuid_generate_random(uu);
57 break;
58 default:
59 uuid_generate(uu);
60 break;
61 }
62
63 uuid_unparse(uu, str);
Theodore Ts'o5d45d801999-03-16 19:35:19 +000064
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000065 printf("%s\n", str);
Theodore Ts'o5d45d801999-03-16 19:35:19 +000066
Theodore Ts'o5dbb0721999-07-03 06:16:06 +000067 return 0;
Theodore Ts'o5d45d801999-03-16 19:35:19 +000068}