UUID: fix seeding the RNG clock on macOS
On Apple machines, call `clock_gettime()` instead of `timespec_get()`. macOS only introduced `timespec_get()` in version 10.15 (introduced approx two years ago, so in 2019), even though the function is from C11.
This commit is contained in:
@@ -39,7 +39,16 @@ UUID BLI_uuid_generate_random()
|
||||
static_assert(std::mt19937_64::max() == 0xffffffffffffffffLL);
|
||||
|
||||
struct timespec ts;
|
||||
#ifdef __APPLE__
|
||||
/* `timespec_get()` is only available on macOS 10.15+, so until that's the minimum version
|
||||
* supported by Blender, use another function to get the timespec.
|
||||
*
|
||||
* `clock_gettime()` is only available on POSIX, so not on Windows; Linux uses the newer C++11
|
||||
* function `timespec_get()` as well. */
|
||||
clock_gettime(CLOCK_REALTIME, &ts);
|
||||
#else
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
#endif
|
||||
/* XOR the nanosecond and second fields, just in case the clock only has seconds resolution. */
|
||||
uint64_t seed = ts.tv_nsec;
|
||||
seed ^= ts.tv_sec;
|
||||
|
Reference in New Issue
Block a user