xref: /aosp_15_r20/external/ltp/include/lapi/getrandom.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2015 Linux Test Project
4  */
5 
6 #ifndef LAPI_GETRANDOM_H__
7 #define LAPI_GETRANDOM_H__
8 
9 #include "config.h"
10 
11 #ifdef HAVE_SYS_RANDOM_H
12 # include <sys/random.h>
13 #elif HAVE_LINUX_RANDOM_H
14 # include <linux/random.h>
15 #endif
16 
17 #include "lapi/syscalls.h"
18 
19 /*
20  * Flags for getrandom(2)
21  *
22  * GRND_NONBLOCK	Don't block and return EAGAIN instead
23  * GRND_RANDOM		Use the /dev/random pool instead of /dev/urandom
24  */
25 
26 #ifndef GRND_NONBLOCK
27 # define GRND_NONBLOCK	0x0001
28 #endif
29 
30 #ifndef GRND_RANDOM
31 # define GRND_RANDOM	0x0002
32 #endif
33 
34 #ifndef HAVE_SYS_RANDOM_H
getrandom(void * buf,size_t buflen,unsigned int flags)35 static inline int getrandom(void *buf, size_t buflen, unsigned int flags)
36 {
37 	return tst_syscall(SYS_getrandom, buf, buflen, flags);
38 }
39 #endif
40 
41 #endif /* LAPI_GETRANDOM_H__ */
42