]> git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/sources/getentropy.c
4d9e2ae4ab2d39f7e6313f95e207f4106e60915b
[wasi-libc.git] / libc-bottom-half / sources / getentropy.c
1 #include <wasi/core.h>
2 #include <errno.h>
3
4 #ifdef _REENTRANT
5 #error With threads support, getentropy is not intended to be a cancellation point.
6 #endif
7
8 int getentropy(void *buffer, size_t len) {
9 if (len > 256) {
10 errno = EIO;
11 return -1;
12 }
13
14 int r = __wasi_random_get(buffer, len);
15
16 if (r != 0) {
17 errno = r;
18 return -1;
19 }
20
21 return 0;
22 }