~pr0gg3d/ubuntu/oneiric/util-linux/bug-805886

« back to all changes in this revision

Viewing changes to misc-utils/uuidgen.c

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2009-07-16 15:48:23 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20090716154823-i26fshvs4v8h90qh
Tags: 2.16-1ubuntu1
* Merge from Debian, remaining changes:
  - Since udev is required in Ubuntu, the hwclock.sh init script is
    not called on startup and the hwclockfirst.sh init script is
    removed.
  - Remove /etc/adjtime on upgrade if it was not used.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - No lsb_release call in mount.preinst since we'd need Pre-Depends
    (LP: #383697).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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"
 
26
 
 
27
#define DO_TYPE_TIME    1
 
28
#define DO_TYPE_RANDOM  2
 
29
 
 
30
static void usage(const char *progname)
 
31
{
 
32
        fprintf(stderr, _("Usage: %s [-r] [-t]\n"), progname);
 
33
        exit(1);
 
34
}
 
35
 
 
36
int
 
37
main (int argc, char *argv[])
 
38
{
 
39
        int    c;
 
40
        int    do_type = 0;
 
41
        char   str[37];
 
42
        uuid_t uu;
 
43
 
 
44
        setlocale(LC_ALL, "");
 
45
        bindtextdomain(PACKAGE, LOCALEDIR);
 
46
        textdomain(PACKAGE);
 
47
 
 
48
        while ((c = getopt (argc, argv, "tr")) != EOF)
 
49
                switch (c) {
 
50
                case 't':
 
51
                        do_type = DO_TYPE_TIME;
 
52
                        break;
 
53
                case 'r':
 
54
                        do_type = DO_TYPE_RANDOM;
 
55
                        break;
 
56
                default:
 
57
                        usage(argv[0]);
 
58
                }
 
59
 
 
60
        switch (do_type) {
 
61
        case DO_TYPE_TIME:
 
62
                uuid_generate_time(uu);
 
63
                break;
 
64
        case DO_TYPE_RANDOM:
 
65
                uuid_generate_random(uu);
 
66
                break;
 
67
        default:
 
68
                uuid_generate(uu);
 
69
                break;
 
70
        }
 
71
 
 
72
        uuid_unparse(uu, str);
 
73
 
 
74
        printf("%s\n", str);
 
75
 
 
76
        return 0;
 
77
}