Declare getentropy in <sys/random.h>

Some systems, such as Darwin, only declare getentropy in <sys/random.h>,
so declare it there on WASI too for compatibility.

Also, give getentropy the underscore-prefix/weak-symbol treatment, as
it's not a standard-reserved identifier.
This commit is contained in:
Dan Gohman 2019-04-30 15:05:10 -07:00
parent 9bb4cc5c41
commit 401012952d
4 changed files with 10 additions and 3 deletions

View File

@ -80,6 +80,7 @@ __fwritex
__fwriting
__get_locale
__getdelim
__getentropy
__getopt_msg
__gmtime_r
__hwcap

View File

@ -711,8 +711,6 @@
#define GLOB_NOSPACE 1
#define GLOB_NOSYS 4
#define GLOB_PERIOD 0x80
#define GRND_NONBLOCK 0x0001
#define GRND_RANDOM 0x0002
#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + (numsrc) * sizeof(struct sockaddr_storage))
#define HFIXEDSZ NS_HFIXEDSZ
#define HIBITL MINLONG

View File

@ -6,7 +6,7 @@
#error With threads support, getentropy is not intended to be a cancellation point.
#endif
int getentropy(void *buffer, size_t len) {
int __getentropy(void *buffer, size_t len) {
if (len > 256) {
errno = EIO;
return -1;
@ -21,3 +21,4 @@ int getentropy(void *buffer, size_t len) {
return 0;
}
extern __typeof(__getentropy) getentropy __attribute__((weak, alias("__getentropy")));

View File

@ -4,6 +4,7 @@
extern "C" {
#endif
#ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */
#define __NEED_size_t
#define __NEED_ssize_t
#include <bits/alltypes.h>
@ -12,6 +13,12 @@ extern "C" {
#define GRND_RANDOM 0x0002
ssize_t getrandom(void *, size_t, unsigned);
#else
#define __NEED_size_t
#include <bits/alltypes.h>
int getentropy(void *, size_t);
#endif
#ifdef __cplusplus
}