X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Futil%2Frand_xor.c;h=81b64f1ea71712a49338e5b77bf9ae166413e671;hb=012b7aab260d4d46c5e2d276485ec693a75cceeb;hp=b34b4e40bfa5233badb8a0b5d78d7dc279294081;hpb=f50f26325f8df7e076a0ffd2196eab1c36ff07ae;p=mesa.git diff --git a/src/util/rand_xor.c b/src/util/rand_xor.c index b34b4e40bfa..81b64f1ea71 100644 --- a/src/util/rand_xor.c +++ b/src/util/rand_xor.c @@ -22,17 +22,18 @@ * */ -#if defined(__linux__) +#include "detect_os.h" + +#if !DETECT_OS_WINDOWS #if defined(HAVE_GETRANDOM) #include #endif -#include #include #include -#else -#include #endif +#include + #include "rand_xor.h" /* Super fast random number generator. @@ -57,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) @@ -70,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); }