]> granicus.if.org Git - musl/commitdiff
add getrandom syscall wrapper
authorHauke Mehrtens <hauke@hauke-m.de>
Sat, 6 Jan 2018 22:08:09 +0000 (23:08 +0100)
committerRich Felker <dalias@aerifal.cx>
Fri, 23 Feb 2018 00:34:58 +0000 (19:34 -0500)
This syscall is available since Linux 3.17 and was also implemented in
glibc in version 2.25 using the same interfaces.

include/sys/random.h [new file with mode: 0644]
src/linux/getrandom.c [new file with mode: 0644]

diff --git a/include/sys/random.h b/include/sys/random.h
new file mode 100644 (file)
index 0000000..4ee7bf2
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _SYS_RANDOM_H
+#define _SYS_RANDOM_H
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define __NEED_size_t
+#define __NEED_ssize_t
+#include <bits/alltypes.h>
+
+#define GRND_NONBLOCK  0x0001
+#define GRND_RANDOM    0x0002
+
+ssize_t getrandom(void *, size_t, unsigned);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/linux/getrandom.c b/src/linux/getrandom.c
new file mode 100644 (file)
index 0000000..6cc6f6b
--- /dev/null
@@ -0,0 +1,7 @@
+#include <sys/random.h>
+#include "syscall.h"
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned flags)
+{
+       return syscall_cp(SYS_getrandom, buf, buflen, flags);
+}