summaryrefslogtreecommitdiff
path: root/src/librandom/random_buf.c
blob: 2c75e97ef988517c883264eb95996914ab082f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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 <skalibs/random.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