Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 105 lines (90 sloc) 2.126 kb
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
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 <stdio.h>
13 #ifdef HAVE_STDLIB_H
14 #include <stdlib.h>
15 #endif
16 #ifdef HAVE_GETOPT_H
17 #include <getopt.h>
18 #else
19 extern int getopt(int argc, char * const argv[], const char *optstring);
20 extern char *optarg;
21 extern int optind;
22 #endif
23
24 #include "uuid.h"
25 #include "nls.h"
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
26 #include "c.h"
c05a80c @kerolasa misc-utils: verify writing to streams was successful
kerolasa authored
27 #include "closestream.h"
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
28
29 #define DO_TYPE_TIME 1
30 #define DO_TYPE_RANDOM 2
31
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
32 static void __attribute__ ((__noreturn__)) usage(FILE * out)
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
33 {
4469776 @karelzak uuidgen: cleanup usage()
authored
34 fputs(_("\nUsage:\n"), out);
35 fprintf(out,
36 _(" %s [options]\n"), program_invocation_short_name);
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
37
4469776 @karelzak uuidgen: cleanup usage()
authored
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);
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
43
44 exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
45 }
46
47 int
48 main (int argc, char *argv[])
49 {
50 int c;
51 int do_type = 0;
52 char str[37];
53 uuid_t uu;
54
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
55 static const struct option longopts[] = {
56 {"random", required_argument, NULL, 'r'},
57 {"time", no_argument, NULL, 't'},
58 {"version", no_argument, NULL, 'V'},
59 {"help", no_argument, NULL, 'h'},
60 {NULL, 0, NULL, 0}
61 };
62
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
63 setlocale(LC_ALL, "");
64 bindtextdomain(PACKAGE, LOCALEDIR);
65 textdomain(PACKAGE);
c05a80c @kerolasa misc-utils: verify writing to streams was successful
kerolasa authored
66 atexit(close_stdout);
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
67
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
68 while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
69 switch (c) {
70 case 't':
71 do_type = DO_TYPE_TIME;
72 break;
73 case 'r':
74 do_type = DO_TYPE_RANDOM;
75 break;
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
76 case 'V':
77 printf(_("%s from %s\n"),
78 program_invocation_short_name,
79 PACKAGE_STRING);
80 return EXIT_SUCCESS;
81 case 'h':
82 usage(stdout);
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
83 default:
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
84 usage(stderr);
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
85 }
86
87 switch (do_type) {
88 case DO_TYPE_TIME:
89 uuid_generate_time(uu);
90 break;
91 case DO_TYPE_RANDOM:
92 uuid_generate_random(uu);
93 break;
94 default:
95 uuid_generate(uu);
96 break;
97 }
98
99 uuid_unparse(uu, str);
100
101 printf("%s\n", str);
102
0379a55 @kerolasa uuidgen: add long options
kerolasa authored
103 return EXIT_SUCCESS;
0140c39 @karelzak uuidgen: new command (from e2fsprogs)
authored
104 }
Something went wrong with that request. Please try again.