summaryrefslogtreecommitdiff
path: root/src/shared/missing.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-10-29 17:06:32 +0100
committerLennart Poettering <lennart@poettering.net>2014-10-29 17:06:32 +0100
commit539618a0ddc2dc7f0fbe28de2ae0e07b34c81e60 (patch)
tree23a4a87b839413ee39636eb116b5316571c88878 /src/shared/missing.h
parentd0159fdc7a1009027f019f763106aa13256cf030 (diff)
util: make use of the new getrandom() syscall if it is available when needing entropy
Doesn't require an fd, and could be a bit faster, so let's make use of it, if it is available.
Diffstat (limited to 'src/shared/missing.h')
-rw-r--r--src/shared/missing.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/shared/missing.h b/src/shared/missing.h
index bb4f8f23a8..5b87e23eec 100644
--- a/src/shared/missing.h
+++ b/src/shared/missing.h
@@ -140,6 +140,21 @@ static inline int memfd_create(const char *name, unsigned int flags) {
}
#endif
+#ifndef __NR_getrandom
+# if defined __x86_64__
+# define __NR_getrandom 278
+# else
+# warning "__NR_getrandom unknown for your architecture"
+# define __NR_getrandom 0xffffffff
+# endif
+#endif
+
+#if !HAVE_DECL_GETRANDOM
+static inline int getrandom(void *buffer, size_t count, unsigned flags) {
+ return syscall(__NR_getrandom, buffer, count, flags);
+}
+#endif
+
#ifndef BTRFS_IOCTL_MAGIC
#define BTRFS_IOCTL_MAGIC 0x94
#endif