From 551571c44e02d06fc41adb148e843a6f3b6326b2 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Wed, 24 Sep 2014 01:07:18 +0000 Subject: [PATCH] die if no namespace provided for v3 or v5 uuid use warn and die implementations in uuidgen --- Makefile | 4 ++-- uuidgen.c | 18 ++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 52d7b7d..4814ee0 100644 --- 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 diff --git a/uuidgen.c b/uuidgen.c index 555b90c..6328e5b 100644 --- a/uuidgen.c +++ b/uuidgen.c @@ -4,6 +4,7 @@ #include #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); -- 2.40.0