Debian Codegraph @

src/vendor/azure-uamqp-c/deps/azure-c-shared-utility/adapters/uniqueid_linux.c

raw
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 #include <stdlib.h>
5 #include <stdint.h>
6 #include <string.h>
7 #include <uuid/uuid.h>
8
9 #include "azure_macro_utils/macro_utils.h"
10 #include "azure_c_shared_utility/uniqueid.h"
11 #include "azure_c_shared_utility/xlogging.h"
12
13 MU_DEFINE_ENUM_STRINGS(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES);
14
15 UNIQUEID_RESULT UniqueId_Generate(char* uid, size_t len)
16 {
17 UNIQUEID_RESULT result;
18
19 /* Codes_SRS_UNIQUEID_07_002: [If uid is NULL then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
20 /* Codes_SRS_UNIQUEID_07_003: [If len is less then 37 then UniqueId_Generate shall return UNIQUEID_INVALID_ARG] */
21 if (uid == NULL || len < 37)
22 {
23 result = UNIQUEID_INVALID_ARG;
24 LogError("Buffer Size is Null. (result = %" PRI_MU_ENUM ")", MU_ENUM_VALUE(UNIQUEID_RESULT, result));
25 }
26 else
27 {
28 uuid_t uuidVal;
29 uuid_generate(uuidVal);
30
31 /* Codes_SRS_UNIQUEID_07_001: [UniqueId_Generate shall create a unique Id 36 character long string.] */
32 memset(uid, 0, len);
33 uuid_unparse(uuidVal, uid);
34 result = UNIQUEID_OK;
35 }
36 return result;
37 }