Skip to content

Commit a1aabdf

Browse files
authored
Merge branch 'main' into cmake-windows
2 parents 257ffd1 + e8a4ac8 commit a1aabdf

File tree

3 files changed

+39
-360
lines changed

3 files changed

+39
-360
lines changed

lib/pal/PAL.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#include "utils/Utils.hpp"
2727
#include <sys/types.h>
2828

29+
#if defined(__APPLE__)
30+
#include <CoreFoundation/CoreFoundation.h>
31+
#endif
32+
2933
#ifndef _WIN32
3034
#ifndef _GNU_SOURCE
3135
#define _GNU_SOURCE
@@ -300,6 +304,32 @@ namespace PAL_NS_BEGIN {
300304
/* CoCreateGuid` will possiblity never fail, so ignoring the result */
301305
UNREFERENCED_PARAMETER(hr);
302306
return MAT::to_string(uuid);
307+
#elif defined(__APPLE__)
308+
auto uuid {CFUUIDCreate(kCFAllocatorDefault)};
309+
if(!uuid)
310+
{
311+
return {};
312+
}
313+
auto uuidStrRef {CFUUIDCreateString(kCFAllocatorDefault, uuid)};
314+
CFRelease(uuid);
315+
if(!uuidStrRef)
316+
{
317+
return {};
318+
}
319+
std::string uuidStr;
320+
if(CFStringGetCStringPtr(uuidStrRef, kCFStringEncodingASCII))
321+
{
322+
uuidStr = CFStringGetCStringPtr(uuidStrRef, kCFStringEncodingASCII);
323+
}
324+
else
325+
{
326+
const auto uuidNullTerminatedSize {CFStringGetLength(uuidStrRef) + 1};
327+
uuidStr.resize(uuidNullTerminatedSize);
328+
CFStringGetCString(uuidStrRef, &uuidStr[0], uuidNullTerminatedSize, kCFStringEncodingASCII);
329+
}
330+
CFRelease(uuidStrRef);
331+
std::transform(uuidStr.begin(), uuidStr.end(), uuidStr.begin(), ::tolower);
332+
return uuidStr;
303333
#else
304334
static std::once_flag flag;
305335
std::call_once(flag, [](){

lib/pal/PseudoRandomGenerator.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace PAL_NS_BEGIN
1010
// Pseudo-random number generator (not for cryptographic usage).
1111
// The instances are not thread-safe, serialize access externally if needed.
1212
class PseudoRandomGenerator {
13-
#ifdef _WIN32
13+
#if defined(_WIN32) || defined (__APPLE__)
1414
public:
1515
double getRandomDouble()
1616
{

0 commit comments

Comments
 (0)