tests: update expect file for u_direct_io
[e2fsprogs.git] / misc / uuidgen.c
blob1233f3df1421921e92c083d8a84c5217fd20df03
1 /*
2 * gen_uuid.c --- generate a DCE-compatible uuid
4 * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o
6 * %Begin-Header%
7 * This file may be redistributed under the terms of the GNU Public
8 * License.
9 * %End-Header%
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
20 extern int getopt(int argc, char * const argv[], const char *optstring);
21 extern char *optarg;
22 extern int optind;
23 #endif
24 #include "uuid/uuid.h"
25 #include "support/nls-enable.h"
27 #define DO_TYPE_TIME 1
28 #define DO_TYPE_RANDOM 2
30 static void usage(const char *progname)
32 fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
33 exit(1);
36 int
37 main (int argc, char *argv[])
39 int c;
40 int do_type = 0;
41 char str[37];
42 uuid_t uu;
44 #ifdef ENABLE_NLS
45 setlocale(LC_MESSAGES, "");
46 setlocale(LC_CTYPE, "");
47 bindtextdomain(NLS_CAT_NAME, LOCALEDIR);
48 textdomain(NLS_CAT_NAME);
49 #endif
51 while ((c = getopt (argc, argv, "tr")) != EOF)
52 switch (c) {
53 case 't':
54 do_type = DO_TYPE_TIME;
55 break;
56 case 'r':
57 do_type = DO_TYPE_RANDOM;
58 break;
59 default:
60 usage(argv[0]);
63 switch (do_type) {
64 case DO_TYPE_TIME:
65 uuid_generate_time(uu);
66 break;
67 case DO_TYPE_RANDOM:
68 uuid_generate_random(uu);
69 break;
70 default:
71 uuid_generate(uu);
72 break;
75 uuid_unparse(uu, str);
77 printf("%s\n", str);
79 return 0;