FreeBSD uuid wrapper fixes
[babeltrace.git] / include / babeltrace / uuid.h
CommitLineData
a4dfa07b
MD
1#ifndef _BABELTRACE_UUID_H
2#define _BABELTRACE_UUID_H
3
4/*
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
7 * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
8 * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
9 *
10 * Permission is hereby granted to use or copy this program
11 * for any purpose, provided the above notices are retained on all copies.
12 * Permission to modify the code and to distribute modified code is granted,
13 * provided the above notices are retained, and a notice that the code was
14 * modified is included with the above copyright notice.
15 */
16
17#include <config.h>
18
19/* Includes final \0. */
20#define BABELTRACE_UUID_STR_LEN 37
21#define BABELTRACE_UUID_LEN 16
22
23#ifdef BABELTRACE_HAVE_LIBUUID
24#include <uuid/uuid.h>
25
26static inline
27int babeltrace_uuid_generate(unsigned char *uuid_out)
28{
29 uuid_generate(uuid_out);
30 return 0;
31}
32
33static inline
57a9f43a 34int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
a4dfa07b 35{
57a9f43a
MD
36 uuid_unparse(uuid_in, str_out);
37 return 0;
a4dfa07b
MD
38}
39
40static inline
41int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
42{
43 return uuid_parse(str_in, uuid_out);
44}
45
46static inline
47int babeltrace_uuid_compare(const unsigned char *uuid_a,
48 const unsigned char *uuid_b)
49{
50 return uuid_compare(uuid_a, uuid_b);
51}
52
53#elif defined(BABELTRACE_HAVE_LIBC_UUID)
54#include <uuid.h>
55#include <stdint.h>
57a9f43a
MD
56#include <string.h>
57#include <stdlib.h>
a4dfa07b
MD
58
59static inline
60int babeltrace_uuid_generate(unsigned char *uuid_out)
61{
62 uint32_t status;
63
64 uuid_create((uuid_t *) uuid_out, &status);
65 if (status == uuid_s_ok)
66 return 0;
67 else
68 return -1;
69}
70
71static inline
57a9f43a 72int babeltrace_uuid_unparse(const unsigned char *uuid_in, char *str_out)
a4dfa07b
MD
73{
74 uint32_t status;
57a9f43a
MD
75 char *alloc_str;
76 int ret;
77
78 uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
79 if (status == uuid_s_ok) {
80 strcpy(str_out, alloc_str);
81 ret = 0;
82 } else {
83 ret = -1;
84 }
85 free(alloc_str);
86 return ret;
a4dfa07b
MD
87}
88
89static inline
90int babeltrace_uuid_parse(const char *str_in, unsigned char *uuid_out)
91{
92 uint32_t status;
93
94 uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
95 if (status == uuid_s_ok)
96 return 0;
97 else
98 return -1;
99}
100
101static inline
102int babeltrace_uuid_compare(const unsigned char *uuid_a,
103 const unsigned char *uuid_b)
104{
105 uint32_t status;
106
107 uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
108 if (status == uuid_s_ok)
109 return 0;
110 else
111 return -1;
112}
113
114#else
115#error "Babeltrace needs to have a UUID generator configured."
116#endif
117
118#endif /* _BABELTRACE_UUID_H */
This page took 0.027437 seconds and 4 git commands to generate.