tests: fopen /dev/urandom in binary mode

This makes a difference with mingw builds on Wine, where the subsequent
fread() may abort early in the default text mode.

The Microsoft C docs say:
"In text mode, CTRL+Z is interpreted as an EOF character on input."
This commit is contained in:
Tim Ruffing 2021-05-01 13:06:55 +02:00 committed by Pieter Wuille
parent 4dc37bf81b
commit ed5a199bed
1 changed files with 1 additions and 1 deletions

View File

@ -127,7 +127,7 @@ static void secp256k1_testrand_init(const char* hexseed) {
pos++;
}
} else {
FILE *frand = fopen("/dev/urandom", "r");
FILE *frand = fopen("/dev/urandom", "rb");
if ((frand == NULL) || fread(&seed16, 1, sizeof(seed16), frand) != sizeof(seed16)) {
uint64_t t = time(NULL) * (uint64_t)1337;
fprintf(stderr, "WARNING: could not read 16 bytes from /dev/urandom; falling back to insecure PRNG\n");