Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 1 | /* |
| 2 | * gen_uuid.c --- generate a DCE-compatible uuid |
| 3 | * |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 4 | * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 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> |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 13 | #ifdef HAVE_GETOPT_H |
| 14 | #include <getopt.h> |
Theodore Ts'o | 373b833 | 2000-04-03 16:22:35 +0000 | [diff] [blame] | 15 | #else |
| 16 | extern char *optarg; |
| 17 | extern int optind; |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 18 | #endif |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 19 | #include "uuid/uuid.h" |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 20 | #include "nls-enable.h" |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 21 | |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 22 | #define DO_TYPE_TIME 1 |
| 23 | #define DO_TYPE_RANDOM 2 |
| 24 | |
| 25 | void usage(const char *progname) |
| 26 | { |
Theodore Ts'o | d9c56d3 | 2000-02-08 00:47:55 +0000 | [diff] [blame] | 27 | fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname); |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 28 | exit(1); |
| 29 | } |
| 30 | |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 31 | int |
| 32 | main (int argc, char *argv[]) |
| 33 | { |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 34 | int c; |
| 35 | int do_type = 0; |
| 36 | char str[37]; |
| 37 | uuid_t uu; |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 38 | |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 39 | 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'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 64 | |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 65 | printf("%s\n", str); |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 66 | |
Theodore Ts'o | 5dbb072 | 1999-07-03 06:16:06 +0000 | [diff] [blame] | 67 | return 0; |
Theodore Ts'o | 5d45d80 | 1999-03-16 19:35:19 +0000 | [diff] [blame] | 68 | } |