]> pd.if.org Git - uuid/commitdiff
die if no namespace provided for v3 or v5 uuid
authorNathan Wagner <nw@hydaspes.if.org>
Wed, 24 Sep 2014 01:07:18 +0000 (01:07 +0000)
committerNathan Wagner <nw@hydaspes.if.org>
Wed, 24 Sep 2014 01:23:58 +0000 (01:23 +0000)
use warn and die implementations in uuidgen

Makefile
uuidgen.c

index 52d7b7d2826b1310b0663f5281403fcb4267a105..4814ee0dad4183bcc7a070683eeec34924ec0653 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -38,8 +38,8 @@ internal.o:   internal.c
 uuidgen2:      libpduuid.a uuidgen2.o
        $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen2.o -lpduuid $(LDFLAGS)
 
-uuidgen:       libpduuid.a uuidgen.o
-       $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o -lpduuid $(LDFLAGS)
+uuidgen:       libpduuid.a uuidgen.o warn.o
+       $(CC) $(CFLAGS) -Wall -L. -o $@ uuidgen.o warn.o -lpduuid $(LDFLAGS)
 
 clean:
        rm -f *.o *.a uuidgen postgres/*.o postgres/*.so
index 555b90c05874d77ba24b3610d23d1232c78cb93b..6328e5be99f53baad2767917c5cfc0203cccdefc 100644 (file)
--- a/uuidgen.c
+++ b/uuidgen.c
@@ -4,6 +4,7 @@
 #include <string.h>
 
 #include "pduuid.h"
+#include "warn.h"
 
 void print_help() {
        printf("uuidgen [-rthV]\n");
@@ -16,7 +17,7 @@ int main(int ac, char *av[]) {
        pd_uuid_t       u; /* generated uuid */
        pd_uuid_t       nsuuid; /* namespace uuid */
        pd_uuid_t       *nsid = 0; /* pointer to namespace uuid */
-       char *ns; /* literal ns id string */
+       char *ns = 0; /* literal ns id string */
 
        struct pd_uuid_state    s;
        char uuid[PD_UUID_STRLEN+1];
@@ -93,9 +94,7 @@ int main(int ac, char *av[]) {
                                q = atoi(optarg);
                                break;
                        default:
-                               fprintf(stderr,
-                                       "uuidgen: unknown option '%c'\n",
-                                       opt);
+                               warn("uuidgen: unknown option '%c'", opt);
                                print_help();
                                exit(EXIT_FAILURE);
                }
@@ -107,6 +106,9 @@ int main(int ac, char *av[]) {
                /* TODO warn if q != 1 */
                int len;
                if (!nsid) {
+                       if (!ns) {
+                               die("must specify namespace for version %d uuids", mode);
+                       }
                        if (!strcmp(ns, "dns")) {
                                nsid = &pd_uuid_ns_dns;
                        } else if (!strcmp(ns, "url")) {
@@ -118,8 +120,7 @@ int main(int ac, char *av[]) {
                        } else {
                                nsid = &nsuuid;
                                if (pd_uuid_set_string(nsid, ns) != 0) {
-                                       fprintf(stderr, "malformed ns uuid: %s\n", ns);
-                                       exit(EXIT_FAILURE);
+                                       die("malformed ns uuid: %s\n", ns);
                                }
                        }
                }
@@ -149,10 +150,7 @@ int main(int ac, char *av[]) {
                                pd_uuid_make_v4(&s, &u);
                                break;
                        default:
-                               fprintf(stderr,
-                                       "uuidgen: unknown uuid version '%d'\n",
-                                       mode);
-                               exit(EXIT_FAILURE);
+                               die("uuidgen: unknown uuid version '%d'\n", mode);
                }
                pd_uuid_get_string(&u, uuid);
                printf("%s\n", uuid);