mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Allow OS-neutral builds for platforms where some versions have arc4random_buf
This commit is contained in:
parent
4a343943bd
commit
b4423029b9
@ -55,10 +55,12 @@ evutil_secure_rng_global_setup_locks_(const int enable_locks)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef _EVENT_HAVE_ARC4RANDOM_BUF
|
|
||||||
static void
|
static void
|
||||||
arc4random_buf(void *buf, size_t n)
|
ev_arc4random_buf(void *buf, size_t n)
|
||||||
{
|
{
|
||||||
|
#ifdef _EVENT_HAVE_ARC4RANDOM_BUF
|
||||||
|
return arc4random_buf(buf, n);
|
||||||
|
#else
|
||||||
unsigned char *b = buf;
|
unsigned char *b = buf;
|
||||||
/* Make sure that we start out with b at a 4-byte alignment; plenty
|
/* Make sure that we start out with b at a 4-byte alignment; plenty
|
||||||
* of CPUs care about this for 32-bit access. */
|
* of CPUs care about this for 32-bit access. */
|
||||||
@ -78,8 +80,8 @@ arc4random_buf(void *buf, size_t n)
|
|||||||
ev_uint32_t u = arc4random();
|
ev_uint32_t u = arc4random();
|
||||||
memcpy(b, &u, n);
|
memcpy(b, &u, n);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#else /* !_EVENT_HAVE_ARC4RANDOM { */
|
#else /* !_EVENT_HAVE_ARC4RANDOM { */
|
||||||
|
|
||||||
@ -122,12 +124,18 @@ evutil_secure_rng_init(void)
|
|||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ev_arc4random_buf(void *buf, size_t n)
|
||||||
|
{
|
||||||
|
arc4random_buf(buf, n);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* } !_EVENT_HAVE_ARC4RANDOM */
|
#endif /* } !_EVENT_HAVE_ARC4RANDOM */
|
||||||
|
|
||||||
void
|
void
|
||||||
evutil_secure_rng_get_bytes(void *buf, size_t n)
|
evutil_secure_rng_get_bytes(void *buf, size_t n)
|
||||||
{
|
{
|
||||||
arc4random_buf(buf, n);
|
ev_arc4random_buf(buf, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user