diff --git a/uuid/uuid.c b/uuid/uuid.c index f5cc7f2160..004af3de6a 100644 --- a/uuid/uuid.c +++ b/uuid/uuid.c @@ -39,6 +39,9 @@ #include #elif defined(_WIN32) #include +#define WIN32_LEAN_AND_MEAN +#include +#include #endif #include @@ -68,9 +71,6 @@ static inline void nanotime(struct timespec *tv) { #elif TARGET_OS_WINDOWS #include -#define WIN32_LEAN_AND_MEAN -#include - static inline void nanotime(struct timespec *tv) { FILETIME ftTime; @@ -83,11 +83,18 @@ static inline void nanotime(struct timespec *tv) { } #endif +#if TARGET_OS_WINDOWS +static inline void read_random(void *buffer, unsigned numBytes) { + BCryptGenRandom(NULL, buffer, numBytes, + BCRYPT_RNG_USE_ENTROPY_IN_BUFFER | BCRYPT_USE_SYSTEM_PREFERRED_RNG); +} +#else static inline void read_random(void *buffer, unsigned numBytes) { int fd = open("/dev/urandom", O_RDONLY); read(fd, buffer, numBytes); close(fd); } +#endif UUID_DEFINE(UUID_NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);