From 367c27cb023e84226c2b54ef5f594997f8e4d70a Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Thu, 18 Mar 2021 09:00:38 -0600 Subject: compat: backport to FreeBSD 12.1 Signed-off-by: Jason A. Donenfeld --- src/compat.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/compat.h b/src/compat.h index 649e7dc..6126e26 100644 --- a/src/compat.h +++ b/src/compat.h @@ -67,5 +67,22 @@ static inline void taskqgroup_drain_all(struct taskqgroup *tqg) gtaskqueue_drain_all(q); } } +#endif + +#if __FreeBSD_version < 1202000 +static inline uint32_t arc4random_uniform(uint32_t bound) +{ + uint32_t ret, max_mod_bound; + + if (bound < 2) + return 0; + max_mod_bound = (1 + ~bound) % bound; + + do { + ret = arc4random(); + } while (ret < max_mod_bound); + + return ret % bound; +} #endif -- cgit v1.2.3-59-g8ed1b