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