summaryrefslogtreecommitdiffstats
path: root/libc-bottom-half/sources/getentropy.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc-bottom-half/sources/getentropy.c')
-rw-r--r--libc-bottom-half/sources/getentropy.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/libc-bottom-half/sources/getentropy.c b/libc-bottom-half/sources/getentropy.c
new file mode 100644
index 0000000..e540e7e
--- /dev/null
+++ b/libc-bottom-half/sources/getentropy.c
@@ -0,0 +1,20 @@
+#include <errno.h>
+#include <unistd.h>
+#include <wasi/api.h>
+
+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;
+}
+weak_alias(__getentropy, getentropy);