/src/openvswitch/lib/uuid.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (c) 2008, 2009, 2010, 2016, 2017 Nicira, Inc. |
2 | | * |
3 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | * you may not use this file except in compliance with the License. |
5 | | * You may obtain a copy of the License at: |
6 | | * |
7 | | * http://www.apache.org/licenses/LICENSE-2.0 |
8 | | * |
9 | | * Unless required by applicable law or agreed to in writing, software |
10 | | * distributed under the License is distributed on an "AS IS" BASIS, |
11 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | * See the License for the specific language governing permissions and |
13 | | * limitations under the License. |
14 | | */ |
15 | | |
16 | | #ifndef UUID_H |
17 | | #define UUID_H 1 |
18 | | |
19 | | #include "util.h" |
20 | | #include "openvswitch/uuid.h" |
21 | | |
22 | | #ifdef __cplusplus |
23 | | extern "C" { |
24 | | #endif |
25 | | |
26 | | /* An initializer or expression for an all-zero UUID. */ |
27 | | #define UUID_ZERO ((struct uuid) { .parts = { 0, 0, 0, 0 } }) |
28 | | |
29 | | /* Formats a UUID as a string, in the conventional format. |
30 | | * |
31 | | * Example: |
32 | | * struct uuid uuid = ...; |
33 | | * printf("This UUID is "UUID_FMT"\n", UUID_ARGS(&uuid)); |
34 | | * |
35 | | */ |
36 | 0 | #define UUID_LEN 36 |
37 | 0 | #define UUID_FMT "%08x-%04x-%04x-%04x-%04x%08x" |
38 | | #define UUID_ARGS(UUID) \ |
39 | 0 | ((unsigned int) ((UUID)->parts[0])), \ |
40 | 0 | ((unsigned int) ((UUID)->parts[1] >> 16)), \ |
41 | 0 | ((unsigned int) ((UUID)->parts[1] & 0xffff)), \ |
42 | 0 | ((unsigned int) ((UUID)->parts[2] >> 16)), \ |
43 | 0 | ((unsigned int) ((UUID)->parts[2] & 0xffff)), \ |
44 | 0 | ((unsigned int) ((UUID)->parts[3])) |
45 | | |
46 | | /* Returns a hash value for 'uuid'. This hash value is the same regardless of |
47 | | * whether we are running on a 32-bit or 64-bit or big-endian or little-endian |
48 | | * architecture. */ |
49 | | static inline size_t |
50 | | uuid_hash(const struct uuid *uuid) |
51 | 0 | { |
52 | 0 | return uuid->parts[0]; |
53 | 0 | } Unexecuted instantiation: json.c:uuid_hash Unexecuted instantiation: dynamic-string.c:uuid_hash |
54 | | |
55 | | /* Returns true if 'a == b', false otherwise. */ |
56 | | static inline bool |
57 | | uuid_equals(const struct uuid *a, const struct uuid *b) |
58 | 0 | { |
59 | 0 | return (a->parts[0] == b->parts[0] |
60 | 0 | && a->parts[1] == b->parts[1] |
61 | 0 | && a->parts[2] == b->parts[2] |
62 | 0 | && a->parts[3] == b->parts[3]); |
63 | 0 | } Unexecuted instantiation: json.c:uuid_equals Unexecuted instantiation: dynamic-string.c:uuid_equals |
64 | | |
65 | | /* Returns the first 'n' hex digits of 'uuid', for 0 < 'n' <= 8. |
66 | | * |
67 | | * This is useful for displaying a few leading digits of the uuid, e.g. to |
68 | | * display 4 digits: |
69 | | * printf("%04x", uuid_prefix(uuid, 4)); |
70 | | */ |
71 | | static inline unsigned int |
72 | | uuid_prefix(const struct uuid *uuid, int digits) |
73 | 0 | { |
74 | 0 | return (uuid->parts[0] >> (32 - 4 * digits)); |
75 | 0 | } Unexecuted instantiation: json.c:uuid_prefix Unexecuted instantiation: dynamic-string.c:uuid_prefix |
76 | | |
77 | | /* Returns a string representation of a UUID. |
78 | | * |
79 | | * The string is allocated on the heap. Ownership of the string is |
80 | | * transferred to the caller. |
81 | | */ |
82 | | static inline char * |
83 | | uuid_to_string(const struct uuid *uuid) |
84 | 0 | { |
85 | 0 | char *data = xmalloc(UUID_LEN + 1); |
86 | |
|
87 | 0 | snprintf(data, UUID_LEN + 1, UUID_FMT, UUID_ARGS(uuid)); |
88 | 0 | return data; |
89 | 0 | } Unexecuted instantiation: json.c:uuid_to_string Unexecuted instantiation: dynamic-string.c:uuid_to_string |
90 | | |
91 | | void uuid_init(void); |
92 | | void uuid_generate(struct uuid *); |
93 | | struct uuid uuid_random(void); |
94 | | void uuid_zero(struct uuid *); |
95 | | bool uuid_is_zero(const struct uuid *); |
96 | | int uuid_compare_3way(const struct uuid *, const struct uuid *); |
97 | | bool uuid_from_string(struct uuid *, const char *); |
98 | | bool uuid_from_string_prefix(struct uuid *, const char *); |
99 | | int uuid_is_partial_string(const char *); |
100 | | int uuid_is_partial_match(const struct uuid *, const char *match); |
101 | | void uuid_set_bits_v4(struct uuid *); |
102 | | |
103 | | #ifdef __cplusplus |
104 | | } |
105 | | #endif |
106 | | |
107 | | #endif /* uuid.h */ |