uuidgen.c revision 9d4507c5b61007df968638623aa1b4c47dae6cf9
1/*
2 * gen_uuid.c --- generate a DCE-compatible uuid
3 *
4 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
5 *
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 "config.h"
13#include <stdio.h>
14#ifdef HAVE_STDLIB_H
15#include <stdlib.h>
16#endif
17#ifdef HAVE_GETOPT_H
18#include <getopt.h>
19#else
20extern int getopt(int argc, char * const argv[], const char *optstring);
21extern char *optarg;
22extern int optind;
23#endif
24#include "uuid/uuid.h"
25#include "nls-enable.h"
26
27#define DO_TYPE_TIME	1
28#define DO_TYPE_RANDOM	2
29
30static void usage(const char *progname)
31{
32	fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
33	exit(1);
34}
35
36int
37main (int argc, char *argv[])
38{
39	int    c;
40	int    do_type = 0;
41	char   str[37];
42	uuid_t uu;
43
44#ifdef ENABLE_NLS
45	setlocale(LC_MESSAGES, "");
46	setlocale(LC_CTYPE, "");
47	bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
48	textdomain(NLS_CAT_NAME);
49	set_com_err_gettext(gettext);
50#endif
51
52	while ((c = getopt (argc, argv, "tr")) != EOF)
53		switch (c) {
54		case 't':
55			do_type = DO_TYPE_TIME;
56			break;
57		case 'r':
58			do_type = DO_TYPE_RANDOM;
59			break;
60		default:
61			usage(argv[0]);
62		}
63
64	switch (do_type) {
65	case DO_TYPE_TIME:
66		uuid_generate_time(uu);
67		break;
68	case DO_TYPE_RANDOM:
69		uuid_generate_random(uu);
70		break;
71	default:
72		uuid_generate(uu);
73		break;
74	}
75
76	uuid_unparse(uu, str);
77
78	printf("%s\n", str);
79
80	return 0;
81}
82