mirror of
https://git.proxmox.com/git/wasi-libc
synced 2025-06-15 09:13:19 +00:00

Some systems, such as Darwin, only declare getentropy in <sys/random.h>, so declare it there on WASI too for compatibility. Also, give getentropy the underscore-prefix/weak-symbol treatment, as it's not a standard-reserved identifier.
25 lines
497 B
C
25 lines
497 B
C
#include <wasi/core.h>
|
|
#include <errno.h>
|
|
#include <unistd.h>
|
|
|
|
#ifdef _REENTRANT
|
|
#error With threads support, getentropy is not intended to be a cancellation point.
|
|
#endif
|
|
|
|
int __getentropy(void *buffer, size_t len) {
|
|
if (len > 256) {
|
|
errno = EIO;
|
|
return -1;
|
|
}
|
|
|
|
int r = __wasi_random_get(buffer, len);
|
|
|
|
if (r != 0) {
|
|
errno = r;
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
extern __typeof(__getentropy) getentropy __attribute__((weak, alias("__getentropy")));
|