static void
ev_arc4random_buf(void *buf, size_t n)
{
-#ifdef _EVENT_HAVE_ARC4RANDOM_BUF
+ unsigned char *b = buf;
+#if defined(_EVENT_HAVE_ARC4RANDOM_BUF) && !defined(__APPLE__)
return arc4random_buf(buf, n);
#else
- unsigned char *b = buf;
+
+#if defined(_EVENT_HAVE_ARC4RANDOM_BUF)
+ /* OSX 10.7 introducd arc4random_buf, so if you build your program
+ * there, you'll get surprised when older versions of OSX fail to run.
+ * To solve this, we can check whether the function pointer is set,
+ * and fall back otherwise. (OSX does this using some linker
+ * trickery.)
+ */
+ if (arc4random_buf) {
+ return arc4random_buf(buf, n);
+ }
+#endif
/* Make sure that we start out with b at a 4-byte alignment; plenty
* of CPUs care about this for 32-bit access. */
if (n >= 4 && ((ev_uintptr_t)b) & 3) {