Date: Wed, 4 Oct 2017 17:29:08 +0000 (UTC) From: Mark Johnston <markj@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r324285 - head/sys/compat/linuxkpi/common/include/linux Message-ID: <201710041729.v94HT80Y049995@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: markj Date: Wed Oct 4 17:29:08 2017 New Revision: 324285 URL: https://svnweb.freebsd.org/changeset/base/324285 Log: 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 Modified: head/sys/compat/linuxkpi/common/include/linux/random.h Modified: head/sys/compat/linuxkpi/common/include/linux/random.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/random.h Wed Oct 4 16:35:58 2017 (r324284) +++ head/sys/compat/linuxkpi/common/include/linux/random.h Wed Oct 4 17:29:08 2017 (r324285) @@ -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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201710041729.v94HT80Y049995>