1 /*
2 * Copyright (C) 2008,2010 Citrix Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published
6 * by the Free Software Foundation; version 2.1 only. with the special
7 * exception on linking described in file LICENSE.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 */
14
15 #ifndef __LIBXL_UUID_H__
16 #define __LIBXL_UUID_H__
17
18 #define LIBXL_UUID_FMT "%02hhx%02hhx%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx"
19 #define LIBXL_UUID_FMTLEN ((2*16)+4) /* 16 hex bytes plus 4 hypens */
20 #define LIBXL__UUID_BYTES(uuid) uuid[0], uuid[1], uuid[2], uuid[3], \
21 uuid[4], uuid[5], uuid[6], uuid[7], \
22 uuid[8], uuid[9], uuid[10], uuid[11], \
23 uuid[12], uuid[13], uuid[14], uuid[15]
24 #define LIBXL_UUID_BYTES(arg) LIBXL__UUID_BYTES((arg).uuid)
25
26 typedef struct {
27 /* UUID as an octet stream in big-endian byte-order. */
28 unsigned char uuid[16];
29 } libxl_uuid;
30
31 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040700
32 #if defined(__linux__)
33
34 #include <uuid/uuid.h>
35 #include <stdint.h>
36
37 #elif defined(__FreeBSD__) || defined(__NetBSD__)
38
39 #include <uuid.h>
40 #include <stdint.h>
41 #include <string.h>
42 #include <stdlib.h>
43 #include <stdio.h>
44 #include <assert.h>
45
46 #else
47
48 #error "Please update libxl_uuid.h for your OS"
49
50 #endif
51 #endif
52
53 int libxl_uuid_is_nil(const libxl_uuid *uuid);
54 void libxl_uuid_generate(libxl_uuid *uuid);
55 int libxl_uuid_from_string(libxl_uuid *uuid, const char *in);
56 void libxl_uuid_copy(libxl_ctx *ctx_opt, libxl_uuid *dst,
57 const libxl_uuid *src);
58 #if defined(LIBXL_API_VERSION) && LIBXL_API_VERSION < 0x040500
libxl_uuid_copy_0x040400(libxl_uuid * dst,const libxl_uuid * src)59 static inline void libxl_uuid_copy_0x040400(libxl_uuid *dst,
60 const libxl_uuid *src)
61 {
62 libxl_uuid_copy(NULL, dst, src);
63 }
64 #define libxl_uuid_copy libxl_uuid_copy_0x040400
65 #endif
66
67 void libxl_uuid_clear(libxl_uuid *uuid);
68 int libxl_uuid_compare(const libxl_uuid *uuid1, const libxl_uuid *uuid2);
69 const uint8_t *libxl_uuid_bytearray_const(const libxl_uuid *uuid);
70 uint8_t *libxl_uuid_bytearray(libxl_uuid *uuid);
71
72 #endif /* __LIBXL_UUID_H__ */
73
74 /*
75 * Local variables:
76 * mode: C
77 * c-basic-offset: 4
78 * indent-tabs-mode: nil
79 * End:
80 */
81