| 1 |
// Copyright (c) Microsoft. All rights reserved. |
| 2 |
// Licensed under the MIT license. See LICENSE file in the project root for full license information. |
| 3 |
|
| 4 |
#ifndef UUID_H |
| 5 |
#define UUID_H |
| 6 |
|
| 7 |
#ifdef __cplusplus |
| 8 |
#include <cstddef> |
| 9 |
#include <cstdint> |
| 10 |
#else |
| 11 |
#include <stddef.h> |
| 12 |
#include <stdint.h> |
| 13 |
#include <stdbool.h> |
| 14 |
#endif /* __cplusplus */ |
| 15 |
|
| 16 |
#include "umock_c/umock_c_prod.h" |
| 17 |
|
| 18 |
#ifdef __cplusplus |
| 19 |
extern "C" { |
| 20 |
#endif /* __cplusplus */ |
| 21 |
|
| 22 |
typedef unsigned char UUID_T[16]; |
| 23 |
|
| 24 |
/* These 2 strings can be conveniently used directly in printf statements |
| 25 |
Notice that PRI_UUID has to be used like any other print format specifier, meaning it |
| 26 |
has to be preceded with % */ |
| 27 |
#define PRI_UUID "02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x" |
| 28 |
#define UUID_FORMAT_VALUES(uuid) \ |
| 29 |
(uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], (uuid)[6], (uuid)[7], \ |
| 30 |
(uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15] |
| 31 |
|
| 32 |
#define UUID_FORMAT_VALUES_OR_NULL(uuid) \ |
| 33 |
((uuid) == NULL) ? 0 : (uuid)[0], ((uuid) == NULL) ? 0 : (uuid)[1], ((uuid) == NULL) ? 0 : (uuid)[2], ((uuid) == NULL) ? 0 : (uuid)[3], \ |
| 34 |
((uuid) == NULL) ? 0 : (uuid)[4], ((uuid) == NULL) ? 0 : (uuid)[5], ((uuid) == NULL) ? 0 : (uuid)[6], ((uuid) == NULL) ? 0 : (uuid)[7], \ |
| 35 |
((uuid) == NULL) ? 0 : (uuid)[8], ((uuid) == NULL) ? 0 : (uuid)[9], ((uuid) == NULL) ? 0 : (uuid)[10], ((uuid) == NULL) ? 0 : (uuid)[11], \ |
| 36 |
((uuid) == NULL) ? 0 : (uuid)[12], ((uuid) == NULL) ? 0 : (uuid)[13], ((uuid) == NULL) ? 0 : (uuid)[14], ((uuid) == NULL) ? 0 : (uuid)[15] \ |
| 37 |
|
| 38 |
/* @brief Generates a true UUID |
| 39 |
* @param uuid A pre-allocated buffer for the bytes of the generated UUID |
| 40 |
* @returns Zero if no failures occur, non-zero otherwise. |
| 41 |
*/ |
| 42 |
MOCKABLE_FUNCTION(, int, UUID_generate, UUID_T*, uuid); |
| 43 |
|
| 44 |
/* @brief Gets the UUID value (byte sequence) of an well-formed UUID string. |
| 45 |
* @param uuid_string A null-terminated well-formed UUID string (e.g., "7f907d75-5e13-44cf-a1a3-19a01a2b4528"). |
| 46 |
* @param uuid Sequence of bytes representing an UUID. |
| 47 |
* @returns Zero if no failures occur, non-zero otherwise. |
| 48 |
*/ |
| 49 |
MOCKABLE_FUNCTION(, int, UUID_from_string, const char*, uuid_string, UUID_T*, uuid); |
| 50 |
|
| 51 |
/* @brief Gets the string representation of the UUID value. |
| 52 |
* @param uuid Sequence of bytes representing an UUID. |
| 53 |
* @returns A null-terminated string representation of the UUID value provided (e.g., "7f907d75-5e13-44cf-a1a3-19a01a2b4528"). |
| 54 |
*/ |
| 55 |
MOCKABLE_FUNCTION(, char*, UUID_to_string, const UUID_T*, uuid); |
| 56 |
|
| 57 |
#ifdef __cplusplus |
| 58 |
} |
| 59 |
#endif |
| 60 |
|
| 61 |
#endif /* UUID_H */ |