From: Mathieu Desnoyers Date: Thu, 1 Mar 2012 22:49:30 +0000 (-0500) Subject: Create BSD wrapper for uuid X-Git-Tag: v1.0.0-pre3~9 X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=a4dfa07bd488d4dd77e558ad9e611415441183e7;hp=300d317acaa3bd38afafe0a440946e6c73e6fd73 Create BSD wrapper for uuid Signed-off-by: Mathieu Desnoyers --- diff --git a/configure.ac b/configure.ac index aac3835a..cb64047b 100644 --- a/configure.ac +++ b/configure.ac @@ -35,10 +35,26 @@ AC_FUNC_MALLOC AC_FUNC_MMAP AC_CHECK_FUNCS([bzero gettimeofday munmap strtoul]) -# Check libuuid -AC_CHECK_LIB([uuid], [uuid_generate], [], - [AC_MSG_ERROR([Cannot find libuuid. Use [LDFLAGS]=-Ldir to specify its location.])] +# Check for libuuid +AC_CHECK_LIB([uuid], [uuid_generate], +[ + AC_DEFINE_UNQUOTED([BABELTRACE_HAVE_LIBUUID], 1, [Has libuuid support.]) + have_libuuid=yes +], +[ + # libuuid not found, check for uuid_create in libc. + AC_CHECK_LIB([c], [uuid_create], + [ + AC_DEFINE_UNQUOTED([BABELTRACE_HAVE_LIBC_UUID], 1, [Has libc uuid support.]) + have_libc_uuid=yes + ], + [ + AC_MSG_ERROR([Cannot find libuuid uuid_generate nor libc uuid_create. Use [LDFLAGS]=-Ldir to specify their location.]) + ]) +] ) +AM_CONDITIONAL([BABELTRACE_BUILD_WITH_LIBUUID], [test "x$have_libuuid" = "xyes"]) +AM_CONDITIONAL([BABELTRACE_BUILD_WITH_LIBC_UUID], [test "x$have_libc_uuid" = "xyes"]) AC_CHECK_LIB([popt], [poptGetContext], [], [AC_MSG_ERROR([Cannot find popt.])] diff --git a/converter/Makefile.am b/converter/Makefile.am index 389a9d98..2622e9ca 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -20,3 +20,10 @@ babeltrace_log_SOURCES = babeltrace-log.c babeltrace_log_LDADD = \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la + +if BABELTRACE_BUILD_WITH_LIBUUID +babeltrace_log_LDADD += -luuid +endif +if BABELTRACE_BUILD_WITH_LIBC_UUID +babeltrace_log_LDADD += -lc +endif diff --git a/converter/babeltrace-log.c b/converter/babeltrace-log.c index 53826c33..ac66a8b0 100644 --- a/converter/babeltrace-log.c +++ b/converter/babeltrace-log.c @@ -37,13 +37,10 @@ #include #include +#include #define USEC_PER_SEC 1000000UL -#ifndef UUID_STR_LEN -#define UUID_STR_LEN 37 /* With \0 */ -#endif - int babeltrace_debug, babeltrace_verbose; static char *s_outputname; @@ -90,14 +87,14 @@ static const char metadata_stream_event_header_timestamp[] = static void print_metadata(FILE *fp) { - char uuid_str[UUID_STR_LEN]; + char uuid_str[BABELTRACE_UUID_STR_LEN]; unsigned int major = 0, minor = 0; int ret; ret = sscanf(VERSION, "%u.%u", &major, &minor); if (ret != 2) fprintf(stderr, "[warning] Incorrect babeltrace version format\n."); - uuid_unparse(s_uuid, uuid_str); + babeltrace_uuid_unparse(s_uuid, uuid_str); fprintf(fp, metadata_fmt, major, minor, diff --git a/formats/ctf/metadata/Makefile.am b/formats/ctf/metadata/Makefile.am index 21ae12aa..a7f633d9 100644 --- a/formats/ctf/metadata/Makefile.am +++ b/formats/ctf/metadata/Makefile.am @@ -18,6 +18,13 @@ libctf_ast_la_SOURCES = ctf-visitor-xml.c \ libctf_ast_la_LIBADD = \ $(top_builddir)/lib/libbabeltrace.la +if BABELTRACE_BUILD_WITH_LIBUUID +libctf_ast_la_LIBADD += -luuid +endif +if BABELTRACE_BUILD_WITH_LIBC_UUID +libctf_ast_la_LIBADD += -lc +endif + noinst_PROGRAMS = ctf-parser-test ctf_parser_test_SOURCES = ctf-parser-test.c diff --git a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c index 56aad2c9..6a577b92 100644 --- a/formats/ctf/metadata/ctf-visitor-generate-io-struct.c +++ b/formats/ctf/metadata/ctf-visitor-generate-io-struct.c @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include "ctf-scanner.h" #include "ctf-parser.h" #include "ctf-ast.h" @@ -234,7 +234,7 @@ int get_unary_uuid(struct bt_list_head *head, uuid_t *uuid) assert(node->u.unary_expression.link == UNARY_LINK_UNKNOWN); assert(i == 0); src_string = node->u.unary_expression.u.string; - ret = uuid_parse(src_string, *uuid); + ret = babeltrace_uuid_parse(src_string, *uuid); } return ret; } @@ -2044,7 +2044,7 @@ int ctf_trace_declaration_visit(FILE *fd, int depth, struct ctf_node *node, stru goto error; } if (CTF_TRACE_FIELD_IS_SET(trace, uuid) - && uuid_compare(uuid, trace->uuid)) { + && babeltrace_uuid_compare(uuid, trace->uuid)) { fprintf(fd, "[error] %s: uuid mismatch\n", __func__); ret = -EPERM; goto error; diff --git a/include/Makefile.am b/include/Makefile.am index e675f9e3..c1bbf103 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -26,4 +26,5 @@ noinst_HEADERS = \ babeltrace/ctf-text/types.h \ babeltrace/ctf/types.h \ babeltrace/ctf/callbacks-internal.h \ - babeltrace/trace-handle-internal.h + babeltrace/trace-handle-internal.h \ + babeltrace/uuid.h diff --git a/include/babeltrace/uuid.h b/include/babeltrace/uuid.h new file mode 100644 index 00000000..dfe1e020 --- /dev/null +++ b/include/babeltrace/uuid.h @@ -0,0 +1,109 @@ +#ifndef _BABELTRACE_UUID_H +#define _BABELTRACE_UUID_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include + +/* Includes final \0. */ +#define BABELTRACE_UUID_STR_LEN 37 +#define BABELTRACE_UUID_LEN 16 + +#ifdef BABELTRACE_HAVE_LIBUUID +#include + +static inline +int babeltrace_uuid_generate(unsigned char *uuid_out) +{ + uuid_generate(uuid_out); + return 0; +} + +static inline +void babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out) +{ + return uuid_unparse(uuid_in, str_out); +} + +static inline +int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out) +{ + return uuid_parse(str_in, uuid_out); +} + +static inline +int babeltrace_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b) +{ + return uuid_compare(uuid_a, uuid_b); +} + +#elif defined(BABELTRACE_HAVE_LIBC_UUID) +#include +#include + +static inline +int babeltrace_uuid_generate(unsigned char *uuid_out) +{ + uint32_t status; + + uuid_create((uuid_t *) uuid_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +static inline +void babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out) +{ + uint32_t status; + + uuid_to_string((uuid_t *) uuid_in, str_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +static inline +int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out) +{ + uint32_t status; + + uuid_from_string(str_in, (uuid_t *) uuid_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +static inline +int babeltrace_uuid_compare(const unsigned char *uuid_a, + const unsigned char *uuid_b) +{ + uint32_t status; + + uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +#else +#error "Babeltrace needs to have a UUID generator configured." +#endif + +#endif /* _BABELTRACE_UUID_H */