X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Frand_xor.c;h=81b64f1ea71712a49338e5b77bf9ae166413e671;hb=84ed2d0980bfa98898606c67e7441bc83da6100e;hp=b486a53343cc40c0ef8bc48969856e8b3063e731;hpb=e0ce684aae83bd6c8129cac09dc98823d786b798;p=mesa.git diff --git a/src/util/rand_xor.c b/src/util/rand_xor.c index b486a53343c..81b64f1ea71 100644 --- a/src/util/rand_xor.c +++ b/src/util/rand_xor.c @@ -22,16 +22,18 @@ * */ -#if defined(__linux__) +#include "detect_os.h" + +#if !DETECT_OS_WINDOWS #if defined(HAVE_GETRANDOM) #include #endif #include #include -#else -#include #endif +#include + #include "rand_xor.h" /* Super fast random number generator. @@ -56,10 +58,14 @@ rand_xorshift128plus(uint64_t seed[2]) void s_rand_xorshift128plus(uint64_t seed[2], bool randomised_seed) { - if (!randomised_seed) - goto fixed_seed; + if (!randomised_seed) { + /* Use a fixed seed */ + seed[0] = 0x3bffb83978e24f88; + seed[1] = 0x9238d5d56c71cd35; + return; + } -#if defined(__linux__) +#if !DETECT_OS_WINDOWS size_t seed_size = sizeof(uint64_t) * 2; #if defined(HAVE_GETRANDOM) @@ -69,27 +75,15 @@ s_rand_xorshift128plus(uint64_t seed[2], bool randomised_seed) #endif int fd = open("/dev/urandom", O_RDONLY); - if (fd < 0) - goto fixed_seed; - - if (read(fd, seed, seed_size) != seed_size) { + if (fd >= 0) { + if (read(fd, seed, seed_size) == seed_size) { + close(fd); + return; + } close(fd); - goto fixed_seed; } - - close(fd); - return; - -#else - seed[0] = 0x3bffb83978e24f88; - seed[1] = time(NULL); - - return; #endif -fixed_seed: - - /* Fallback to a fixed seed */ seed[0] = 0x3bffb83978e24f88; - seed[1] = 0x9238d5d56c71cd35; + seed[1] = time(NULL); }