Add get_random_{int,long} to the LinuxKPI.

Fix some whitespace bugs while here.

Reviewed by:	hselasky
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D12588
This commit is contained in:
Mark Johnston 2017-10-04 17:29:08 +00:00
parent 27f0f2ec5f
commit bf4e2e5be1

View file

@ -28,7 +28,8 @@
*
* $FreeBSD$
*/
#ifndef _LINUX_RANDOM_H_
#ifndef _LINUX_RANDOM_H_
#define _LINUX_RANDOM_H_
#include <sys/random.h>
@ -37,8 +38,27 @@
static inline void
get_random_bytes(void *buf, int nbytes)
{
if (read_random(buf, nbytes) == 0)
arc4rand(buf, nbytes, 0);
}
#endif /* _LINUX_RANDOM_H_ */
static inline u_int
get_random_int(void)
{
u_int val;
get_random_bytes(&val, sizeof(val));
return (val);
}
static inline u_long
get_random_long(void)
{
u_long val;
get_random_bytes(&val, sizeof(val));
return (val);
}
#endif /* _LINUX_RANDOM_H_ */