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