#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/time.h>
-#include <unistd.h>
+#include <sys/random.h>
#include "gettext.h"
#define _(msgid) gettext (msgid)
char *buf = buffer, *buflim = buf + bufsize;
while (buf < buflim)
{
- int getentropy_bound = 256;
- int nbytes = MIN (buflim - buf, getentropy_bound);
- if (getentropy (buf, nbytes) != 0)
+ ssize_t nbytes = getrandom (buf, buflim - buf, 0);
+ if (0 <= nbytes)
+ buf += nbytes;
+ else if (errno != EINTR)
return false;
- buf += nbytes;
}
return true;
}
exitfail
inline
fopen-safer
-getentropy
+getrandom
quote
stdalign
stdbool
randint_source = randint_all_new (random_source, SIZE_MAX);
if (! randint_source)
die (EXIT_FAILURE, errno, "%s",
- quotef (random_source ? random_source : "getentropy"));
+ quotef (random_source ? random_source : "getrandom"));
atexit (clear_random_data);
for (i = 0; i < n_files; i++)
: randperm_bound (ahead_lines, n_lines)));
if (! randint_source)
die (EXIT_FAILURE, errno, "%s",
- quotef (random_source ? random_source : "getentropy"));
+ quotef (random_source ? random_source : "getrandom"));
if (use_reservoir_sampling)
{
unsigned char buf[MD5_DIGEST_SIZE];
struct randread_source *r = randread_new (random_source, sizeof buf);
if (! r)
- sort_die (_("open failed"), random_source ? random_source : "getentropy");
+ sort_die (_("open failed"), random_source ? random_source : "getrandom");
randread (r, buf, sizeof buf);
if (randread_free (r) != 0)
sort_die (_("close failed"), random_source);