]>
git.proxmox.com Git - ovs.git/blob - lib/uuid.h
1 /* Copyright (c) 2008, 2009, 2010, 2016, 2017 Nicira, Inc.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "openvswitch/uuid.h"
21 /* An initializer or expression for an all-zero UUID. */
22 #define UUID_ZERO ((struct uuid) { .parts = { 0, 0, 0, 0 } })
24 /* Formats a UUID as a string, in the conventional format.
27 * struct uuid uuid = ...;
28 * printf("This UUID is "UUID_FMT"\n", UUID_ARGS(&uuid));
32 #define UUID_FMT "%08x-%04x-%04x-%04x-%04x%08x"
33 #define UUID_ARGS(UUID) \
34 ((unsigned int) ((UUID)->parts[0])), \
35 ((unsigned int) ((UUID)->parts[1] >> 16)), \
36 ((unsigned int) ((UUID)->parts[1] & 0xffff)), \
37 ((unsigned int) ((UUID)->parts[2] >> 16)), \
38 ((unsigned int) ((UUID)->parts[2] & 0xffff)), \
39 ((unsigned int) ((UUID)->parts[3]))
41 /* Returns a hash value for 'uuid'. This hash value is the same regardless of
42 * whether we are running on a 32-bit or 64-bit or big-endian or little-endian
45 uuid_hash(const struct uuid
*uuid
)
47 return uuid
->parts
[0];
50 /* Returns true if 'a == b', false otherwise. */
52 uuid_equals(const struct uuid
*a
, const struct uuid
*b
)
54 return (a
->parts
[0] == b
->parts
[0]
55 && a
->parts
[1] == b
->parts
[1]
56 && a
->parts
[2] == b
->parts
[2]
57 && a
->parts
[3] == b
->parts
[3]);
61 void uuid_generate(struct uuid
*);
62 struct uuid
uuid_random(void);
63 void uuid_zero(struct uuid
*);
64 bool uuid_is_zero(const struct uuid
*);
65 int uuid_compare_3way(const struct uuid
*, const struct uuid
*);
66 bool uuid_from_string(struct uuid
*, const char *);
67 bool uuid_from_string_prefix(struct uuid
*, const char *);
68 int uuid_is_partial_string(const char *);
69 int uuid_is_partial_match(const struct uuid
*, const char *match
);
70 void uuid_set_bits_v4(struct uuid
*);