Create BSD wrapper for uuid
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 22:49:30 +0000 (17:49 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 1 Mar 2012 22:49:30 +0000 (17:49 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
configure.ac
converter/Makefile.am
converter/babeltrace-log.c
formats/ctf/metadata/Makefile.am
formats/ctf/metadata/ctf-visitor-generate-io-struct.c
include/Makefile.am
include/babeltrace/uuid.h [new file with mode: 0644]

index aac3835a917bf1ee9489ddd2a2ed5b2fafb537d2..cb64047b2aba4a3a90fb0cc61462b9a4326adbda 100644 (file)
@@ -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.])]
index 389a9d98a84c8fe4e851334533266b443693f448..2622e9ca67a00a90738f247747539fd14411bb52 100644 (file)
@@ -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
index 53826c33ee32e12838e952ac680a5127c41fe985..ac66a8b08d878e2be09548be0320d2a3bb0321fc 100644 (file)
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/ctf/types.h>
+#include <babeltrace/uuid.h>
 
 #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,
index 21ae12aaba1af7d2abd09bb5cb154b598a2ed1d8..a7f633d9b0f013476068674eeb050dbf6f8de8fc 100644 (file)
@@ -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
 
index 56aad2c9218832fb3878faa2c5d04ee332736f25..6a577b92be8396fc077980233c03e2b7991bfb64 100644 (file)
@@ -29,7 +29,7 @@
 #include <babeltrace/list.h>
 #include <babeltrace/types.h>
 #include <babeltrace/ctf/metadata.h>
-#include <uuid/uuid.h>
+#include <babeltrace/uuid.h>
 #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;
index e675f9e3724111cef25466ec8f7188b0e42b2275..c1bbf1038231c152bc06c42188aaae9e9af0f7be 100644 (file)
@@ -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 (file)
index 0000000..dfe1e02
--- /dev/null
@@ -0,0 +1,109 @@
+#ifndef _BABELTRACE_UUID_H
+#define _BABELTRACE_UUID_H
+
+/*
+ * Copyright (C) 2011   Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * 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 <config.h>
+
+/* Includes final \0. */
+#define BABELTRACE_UUID_STR_LEN                37
+#define BABELTRACE_UUID_LEN            16
+
+#ifdef BABELTRACE_HAVE_LIBUUID
+#include <uuid/uuid.h>
+
+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 <uuid.h>
+#include <stdint.h>
+
+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 */
This page took 0.05438 seconds and 4 git commands to generate.