-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[util][build] Add UUID generation methods
Links to libuuid on Linux, which comes with util-linux. On Windows it uses rpc.h's UuidCreate method. UUIDs will be used as globally unique preset identifiers.
- Loading branch information
1 parent
7d15447
commit 47e43fd
Showing
3 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include "uuid.h" | ||
|
||
#ifdef _WIN32 | ||
#include <rpc.h> | ||
#elif defined __linux__ | ||
#include <uuid/uuid.h> | ||
#endif | ||
|
||
std::string uuid4() { | ||
auto uuid_str = (char*)malloc(37); | ||
uuid_str[36] = '\0'; | ||
#ifdef _WIN32 | ||
UUID uuid; | ||
UuidCreate(&uuid); | ||
UuidToString(&uuid, (unsigned char**)&uuid_str); | ||
#elif defined __linux__ | ||
uuid_t uuid; | ||
uuid_generate(uuid); | ||
uuid_unparse_lower(uuid, uuid_str); | ||
#endif | ||
auto retval = std::string(uuid_str); | ||
free(uuid_str); | ||
return retval; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include <string> | ||
|
||
std::string uuid4(); |