-
Notifications
You must be signed in to change notification settings - Fork 9
/
guid.h
44 lines (35 loc) · 1.56 KB
/
guid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) 2008 David Caldwell, All Rights Reserved.
#ifndef __GUID_H__
#define __GUID_H__
typedef struct GUID {
unsigned char byte[16];
} GUID;
extern GUID bad_guid;
#define _0x(x) 0x##x##LL
// This encodes the GUID as little endian (which confusingly means the last 2 parts are big-endian)
#define GUID(a,b,c,d,e) (struct GUID) STATIC_GUID(a,b,c,d,e)
#define STATIC_GUID(a,b,c,d,e) { \
{ _0x(a) >> 0 & 0xff, \
_0x(a) >> 8 & 0xff, \
_0x(a) >> 16 & 0xff, \
_0x(a) >> 24 & 0xff, \
_0x(b) >> 0 & 0xff, \
_0x(b) >> 8 & 0xff, \
_0x(c) >> 0 & 0xff, \
_0x(c) >> 8 & 0xff, \
_0x(d) >> 8 & 0xff, \
_0x(d) >> 0 & 0xff, \
_0x(e) >> 40 & 0xff, \
_0x(e) >> 32 & 0xff, \
_0x(e) >> 24 & 0xff, \
_0x(e) >> 16 & 0xff, \
_0x(e) >> 8 & 0xff, \
_0x(e) >> 0 & 0xff \
} }
char *guid_str(); // convenience function. Returns a static char, so strdup before calling
// again. Obviously not thread safe, but it's convenient. :-)
GUID guid_from_string(char *guid);
GUID guid_create();
#include <string.h>
static inline int guid_eq(GUID a, GUID b) { return memcmp(a.byte, b.byte, sizeof(a.byte)) == 0; }
#endif /* __GUID_H__ */