diff options
Diffstat (limited to 'src/librandom/random_buf.c')
-rw-r--r-- | src/librandom/random_buf.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/librandom/random_buf.c b/src/librandom/random_buf.c new file mode 100644 index 0000000..99cce38 --- /dev/null +++ b/src/librandom/random_buf.c @@ -0,0 +1,55 @@ +/* ISC license. */ + +#include <skalibs/sysdeps.h> + +#if defined(SKALIBS_HASARC4RANDOM) + +#include <skalibs/nonposix.h> +#include <stdlib.h> + +#include <skalibs/random.h> + +void random_buf (char *s, size_t n) +{ + arc4random_buf(s, n) ; +} + +#elif defined(SKALIBS_HASGETRANDOM) + +#include <sys/random.h> + +#include <skalibs/random.h> + +void random_buf (char *s, size_t n) +{ + while (n) + { + ssize_t r = getrandom(s, n, 0) ; + if (r >= 0) + { + s += r ; + n -= r ; + } + } +} + +#elif defined(SKALIBS_HASDEVURANDOM) + +#include "random-internal.h" + +void random_buf (char *s, size_t n) +{ + random_devurandom(s, n) ; +} + +#else + +#include <skalibs/surf.h> +#include <skalibs/random.h> + +void random_buf (char *s, size_t n) +{ + autosurf(s, n) ; +} + +#endif |