]> git.ipfire.org Git - thirdparty/util-linux.git/blame - misc-utils/uuidgen.c
misc: cosmetics, remove argument from usage(FILE*)
[thirdparty/util-linux.git] / misc-utils / uuidgen.c
CommitLineData
0140c397
KZ
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>
0140c397 13#include <stdlib.h>
0140c397 14#include <getopt.h>
0140c397
KZ
15
16#include "uuid.h"
17#include "nls.h"
0379a55d 18#include "c.h"
c05a80ca 19#include "closestream.h"
0140c397 20
86be6a32 21static void __attribute__((__noreturn__)) usage(void)
0140c397 22{
86be6a32 23 FILE *out = stdout;
db433bf7 24 fputs(USAGE_HEADER, out);
44697763
KZ
25 fprintf(out,
26 _(" %s [options]\n"), program_invocation_short_name);
0379a55d 27
451dbcfa
BS
28 fputs(USAGE_SEPARATOR, out);
29 fputs(_("Create a new UUID value.\n"), out);
30
db433bf7 31 fputs(USAGE_OPTIONS, out);
504c03ec
SK
32 fputs(_(" -r, --random generate random-based uuid\n"), out);
33 fputs(_(" -t, --time generate time-based uuid\n"), out);
34 fputs(USAGE_SEPARATOR, out);
35 fputs(USAGE_HELP, out);
36 fputs(USAGE_VERSION, out);
a587cc55 37 fprintf(out, USAGE_MAN_TAIL("uuidgen(1)"));
86be6a32 38 exit(EXIT_SUCCESS);
0140c397
KZ
39}
40
41int
42main (int argc, char *argv[])
43{
44 int c;
45 int do_type = 0;
46 char str[37];
47 uuid_t uu;
48
0379a55d 49 static const struct option longopts[] = {
71383195 50 {"random", no_argument, NULL, 'r'},
0379a55d
SK
51 {"time", no_argument, NULL, 't'},
52 {"version", no_argument, NULL, 'V'},
53 {"help", no_argument, NULL, 'h'},
54 {NULL, 0, NULL, 0}
55 };
56
0140c397
KZ
57 setlocale(LC_ALL, "");
58 bindtextdomain(PACKAGE, LOCALEDIR);
59 textdomain(PACKAGE);
c05a80ca 60 atexit(close_stdout);
0140c397 61
0379a55d 62 while ((c = getopt_long(argc, argv, "rtVh", longopts, NULL)) != -1)
0140c397
KZ
63 switch (c) {
64 case 't':
6328799d 65 do_type = UUID_TYPE_DCE_TIME;
0140c397
KZ
66 break;
67 case 'r':
6328799d 68 do_type = UUID_TYPE_DCE_RANDOM;
0140c397 69 break;
0379a55d 70 case 'V':
e421313d 71 printf(UTIL_LINUX_VERSION);
0379a55d
SK
72 return EXIT_SUCCESS;
73 case 'h':
86be6a32 74 usage();
0140c397 75 default:
677ec86c 76 errtryhelp(EXIT_FAILURE);
0140c397
KZ
77 }
78
79 switch (do_type) {
6328799d 80 case UUID_TYPE_DCE_TIME:
0140c397
KZ
81 uuid_generate_time(uu);
82 break;
6328799d 83 case UUID_TYPE_DCE_RANDOM:
0140c397
KZ
84 uuid_generate_random(uu);
85 break;
86 default:
87 uuid_generate(uu);
88 break;
89 }
90
91 uuid_unparse(uu, str);
92
93 printf("%s\n", str);
94
0379a55d 95 return EXIT_SUCCESS;
0140c397 96}