]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/random.h
bcache in userspace; userspace fsck
[bcachefs-tools-debian] / include / linux / random.h
1 /*
2  * include/linux/random.h
3  *
4  * Include file for the random number generator.
5  */
6 #ifndef _LINUX_RANDOM_H
7 #define _LINUX_RANDOM_H
8
9 #include <unistd.h>
10 #include <sys/syscall.h>
11 #include <linux/bug.h>
12
13 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
14 {
15          return syscall(SYS_getrandom, buf, buflen, flags);
16 }
17
18 static inline void get_random_bytes(void *buf, int nbytes)
19 {
20         BUG_ON(getrandom(buf, nbytes, 0) != nbytes);
21 }
22
23 static inline int get_random_int(void)
24 {
25         int v;
26
27         get_random_bytes(&v, sizeof(v));
28         return v;
29 }
30
31 #endif /* _LINUX_RANDOM_H */