--- /dev/null
+# linux-getrandom-userspace
+
+## Overview
+
+Since Linux 3.17 there is a system call `getrandom()`. This was added to glibc 2.25.
+
+This library can be used with `LD_PRELOAD` if you're using Linux 3.16 or earlier and need to run an application which requires `getrandom()`.
+
+See [LWN's The long road to getrandom() in glibc](https://lwn.net/Articles/711013/) for more information.
+
+## Usage
+
+```
+make
+LD_PRELOAD="${PWD}/getrandom.so" mail
+```
--- /dev/null
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/random.h>
+
+ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
+ char* filename = flags & GRND_RANDOM ? "/dev/random" : "/dev/urandom";
+ int nonblock = flags & GRND_NONBLOCK ? O_NONBLOCK : 0;
+ int oflags = O_CLOEXEC | nonblock;
+
+ int fd = open(filename, oflags);
+ if (fd < 0) {
+ return -1;
+ }
+
+ ssize_t bytes = read(fd, buf, buflen);
+
+ close(fd);
+
+ return bytes;
+}