Skip to content

Commit 64471fb

Browse files
committed
CDRIVER-4234 Detect arc4random_buf using cmake
Detect the availability of arc4random_buf when running cmake rather than using a hardcoded list of platforms on which it is available. Fixes build failure on Mac OS X 10.6 where it is not available.
1 parent 80f7105 commit 64471fb

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/libbson/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ else ()
7373
set (BSON_HAVE_GMTIME_R 1)
7474
endif ()
7575

76+
CHECK_SYMBOL_EXISTS (arc4random_buf stdlib.h BSON_HAVE_ARC4RANDOM_BUF)
77+
if (NOT BSON_HAVE_ARC4RANDOM_BUF)
78+
set (BSON_HAVE_ARC4RANDOM_BUF 0)
79+
else ()
80+
set (BSON_HAVE_ARC4RANDOM_BUF 1)
81+
endif ()
82+
7683
CHECK_FUNCTION_EXISTS (rand_r BSON_HAVE_RAND_R)
7784
if (NOT BSON_HAVE_RAND_R)
7885
set (BSON_HAVE_RAND_R 0)

src/libbson/src/bson/bson-config.h.in

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@
114114
#endif
115115

116116

117+
/*
118+
* Define to 1 if you have arc4random_buf available on your platform.
119+
*/
120+
#define BSON_HAVE_ARC4RANDOM_BUF @BSON_HAVE_ARC4RANDOM_BUF@
121+
#if BSON_HAVE_ARC4RANDOM_BUF != 1
122+
# undef BSON_HAVE_ARC4RANDOM_BUF
123+
#endif
124+
125+
117126
/*
118127
* Define to 1 if you have rand_r available on your platform.
119128
*/

src/libbson/src/bson/bson-context.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ _get_rand (unsigned int *pseed)
229229
/* ms's runtime is multithreaded by default, so no rand_r */
230230
/* no rand_r on android either */
231231
result = rand ();
232-
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || \
233-
defined(__OpenBSD__) || defined(__APPLE__)
232+
#elif defined(BSON_HAVE_ARC4RANDOM_BUF)
234233
arc4random_buf (&result, sizeof (result));
235234
#else
236235
result = rand_r (pseed);

0 commit comments

Comments
 (0)