diff options
author | Theodore Ts'o <tytso@mit.edu> | 1999-07-03 06:16:06 +0000 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 1999-07-03 06:16:06 +0000 |
commit | 5dbb072e27bea6f740822590e348da6ae4db2d60 (patch) | |
tree | 9ba4d4d67480802e11f5c99740d54d5f78817f3b /misc/uuidgen.c | |
parent | d44ae132f20785576b10ce75714d7779b099bc54 (diff) | |
download | e2fsprogs-5dbb072e27bea6f740822590e348da6ae4db2d60.tar.gz |
ChangeLog, uuidgen.1.in, uuidgen.c:
uuidgen.c: Add option parsing so that user can ask for either a
time-based UUID or a random-based UUID.
Diffstat (limited to 'misc/uuidgen.c')
-rw-r--r-- | misc/uuidgen.c | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/misc/uuidgen.c b/misc/uuidgen.c index 2b467e99..da402c8a 100644 --- a/misc/uuidgen.c +++ b/misc/uuidgen.c @@ -1,7 +1,7 @@ /* * gen_uuid.c --- generate a DCE-compatible uuid * - * Copyright (C) 1999, Andreas Dilger + * Copyright (C) 1999, Andreas Dilger and Theodore Ts'o * * %Begin-Header% * This file may be redistributed under the terms of the GNU Public @@ -10,18 +10,55 @@ */ #include <stdio.h> +#ifdef HAVE_GETOPT_H +#include <getopt.h> +#endif #include "uuid/uuid.h" +#define DO_TYPE_TIME 1 +#define DO_TYPE_RANDOM 2 + +void usage(const char *progname) +{ + fprintf(stderr, "Usage: %s [-r] [-t]\n", progname); + exit(1); +} + int main (int argc, char *argv[]) { - char str[37]; - uuid_t uu; + int c; + int do_type = 0; + char str[37]; + uuid_t uu; - uuid_generate(uu); - uuid_unparse(uu, str); + while ((c = getopt (argc, argv, "tr")) != EOF) + switch (c) { + case 't': + do_type = DO_TYPE_TIME; + break; + case 'r': + do_type = DO_TYPE_RANDOM; + break; + default: + usage(argv[0]); + } + + switch (do_type) { + case DO_TYPE_TIME: + uuid_generate_time(uu); + break; + case DO_TYPE_RANDOM: + uuid_generate_random(uu); + break; + default: + uuid_generate(uu); + break; + } + + uuid_unparse(uu, str); - printf("%s\n", str); + printf("%s\n", str); - return 0; + return 0; } |