aboutsummaryrefslogtreecommitdiff
path: root/auto/getrandom
blob: 5b5aa19829355be18bb6eb14901f71af0850bfeb (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright (C) Igor Sysoev
# Copyright (C) NGINX, Inc.


# Linux 3.17 with glibc 2.25, FreeBSD 12, Solaris 11.3.

njs_feature="getrandom()"
njs_feature_name=NJS_HAVE_GETRANDOM
njs_feature_run=yes
njs_feature_incs=
njs_feature_libs=
njs_feature_test="#include <unistd.h>
                  #include <sys/random.h>

                  int main(void) {
                      char  buf[4];

                      if (getrandom(buf, 4, 0) < 0) {
                          return 1;
                      }

                      return 0;
                  }"
. auto/feature


if [ $njs_found = no ]; then

    # Linux 3.17 SYS_getrandom.

    njs_feature="SYS_getrandom in Linux"
    njs_feature_name=NJS_HAVE_LINUX_SYS_GETRANDOM
    njs_feature_test="#include <unistd.h>
                      #include <sys/syscall.h>
                      #include <linux/random.h>

                      int main(void) {
                          char  buf[4];

                          if (syscall(SYS_getrandom, buf, 4, 0) < 0) {
                              return 1;
                          }

                          return 0;
                      }"
    . auto/feature
fi


if [ $njs_found = no ]; then

    # macOS 10.10.

    njs_feature="CCRandomGenerateBytes() in CommonCrypto/CommonRandom.h"
    njs_feature_name=NJS_HAVE_CCRANDOMGENERATEBYTES
    njs_feature_test="#include <CommonCrypto/CommonCryptoError.h>
                      #include <CommonCrypto/CommonRandom.h>

                      int main(void) {
                          char  buf[4];

                          if (CCRandomGenerateBytes(buf, 4) != kCCSuccess) {
                              return 1;
                          }

                          return 0;
                      }"
    . auto/feature
fi


if [ $njs_found = no ]; then

    # OpenBSD 5.6 lacks <sys/random.h>.

    njs_feature="getentropy()"
    njs_feature_name=NJS_HAVE_GETENTROPY
    njs_feature_test="#include <unistd.h>

                      int main(void) {
                          char  buf[4];

                          if (getentropy(buf, 4) == -1) {
                              return 1;
                          }

                          return 0;
                      }"
    . auto/feature
fi


if [ $njs_found = no ]; then

    # Solaris based systems.

    njs_feature="getentropy() in sys/random.h"
    njs_feature_name=NJS_HAVE_GETENTROPY_SYS_RANDOM
    njs_feature_test="#include <unistd.h>
                      #include <sys/random.h>

                      int main(void) {
                          char  buf[4];

                          if (getentropy(buf, 4) == -1) {
                              return 1;
                          }

                          return 0;
                      }"
    . auto/feature
fi