lib: Reset libbabeltrace2 to SONANE 0
[babeltrace.git] / include / babeltrace / compat / uuid-internal.h
CommitLineData
9d1e7de0
JI
1#ifndef _BABELTRACE_COMPAT_UUID_H
2#define _BABELTRACE_COMPAT_UUID_H
a4dfa07b
MD
3
4/*
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
6 *
eb31c5e6
MD
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
a4dfa07b 13 *
eb31c5e6
MD
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
c462e188
MD
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
a4dfa07b
MD
24 */
25
a4dfa07b
MD
26/* Includes final \0. */
27#define BABELTRACE_UUID_STR_LEN 37
28#define BABELTRACE_UUID_LEN 16
29
30#ifdef BABELTRACE_HAVE_LIBUUID
31#include <uuid/uuid.h>
32
33static inline
19dd40db 34int bt_uuid_generate(unsigned char *uuid_out)
a4dfa07b
MD
35{
36 uuid_generate(uuid_out);
37 return 0;
38}
39
8a01ca57
MJ
40/* Sun's libuuid lacks const qualifiers */
41#if defined(__sun__)
42static inline
19dd40db 43int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
8a01ca57
MJ
44{
45 uuid_unparse((unsigned char *) uuid_in, str_out);
46 return 0;
47}
48
49static inline
19dd40db 50int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
8a01ca57
MJ
51{
52 return uuid_parse((char *) str_in, uuid_out);
53}
54
55static inline
19dd40db 56int bt_uuid_compare(const unsigned char *uuid_a,
8a01ca57
MJ
57 const unsigned char *uuid_b)
58{
59 return uuid_compare((unsigned char *) uuid_a,
60 (unsigned char *) uuid_b);
61}
62#else
a4dfa07b 63static inline
19dd40db 64int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
a4dfa07b 65{
57a9f43a
MD
66 uuid_unparse(uuid_in, str_out);
67 return 0;
a4dfa07b
MD
68}
69
70static inline
19dd40db 71int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
a4dfa07b
MD
72{
73 return uuid_parse(str_in, uuid_out);
74}
75
76static inline
19dd40db 77int bt_uuid_compare(const unsigned char *uuid_a,
a4dfa07b
MD
78 const unsigned char *uuid_b)
79{
80 return uuid_compare(uuid_a, uuid_b);
81}
8a01ca57 82#endif
a4dfa07b 83
f2c00dfa 84#elif defined(BABELTRACE_HAVE_LIBC_UUID)
a4dfa07b
MD
85#include <uuid.h>
86#include <stdint.h>
57a9f43a
MD
87#include <string.h>
88#include <stdlib.h>
a4dfa07b
MD
89
90static inline
19dd40db 91int bt_uuid_generate(unsigned char *uuid_out)
a4dfa07b
MD
92{
93 uint32_t status;
94
95 uuid_create((uuid_t *) uuid_out, &status);
96 if (status == uuid_s_ok)
97 return 0;
98 else
99 return -1;
100}
101
102static inline
19dd40db 103int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
a4dfa07b
MD
104{
105 uint32_t status;
57a9f43a
MD
106 char *alloc_str;
107 int ret;
108
109 uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
110 if (status == uuid_s_ok) {
111 strcpy(str_out, alloc_str);
112 ret = 0;
113 } else {
114 ret = -1;
115 }
116 free(alloc_str);
117 return ret;
a4dfa07b
MD
118}
119
120static inline
19dd40db 121int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
a4dfa07b
MD
122{
123 uint32_t status;
124
125 uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
126 if (status == uuid_s_ok)
127 return 0;
128 else
129 return -1;
130}
131
132static inline
19dd40db 133int bt_uuid_compare(const unsigned char *uuid_a,
a4dfa07b
MD
134 const unsigned char *uuid_b)
135{
136 uint32_t status;
137
138 uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
139 if (status == uuid_s_ok)
140 return 0;
141 else
142 return -1;
143}
144
9d1e7de0
JI
145#elif defined(__MINGW32__)
146
19dd40db
JG
147int bt_uuid_generate(unsigned char *uuid_out);
148int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out);
149int bt_uuid_parse(const char *str_in, unsigned char *uuid_out);
150int bt_uuid_compare(const unsigned char *uuid_a,
9d1e7de0
JI
151 const unsigned char *uuid_b);
152
a4dfa07b
MD
153#else
154#error "Babeltrace needs to have a UUID generator configured."
155#endif
156
9d1e7de0 157#endif /* _BABELTRACE_COMPAT_UUID_H */
This page took 0.058252 seconds and 4 git commands to generate.