mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-25 17:12:03 +00:00
Add libglibc-compatibility/musl/getentropy.c
This commit is contained in:
parent
6e3f7f62eb
commit
0fff8a785b
@ -19,6 +19,7 @@ musl/sched_cpucount.c
|
||||
musl/glob.c
|
||||
musl/exp2f.c
|
||||
musl/pwritev.c
|
||||
musl/getentropy.c
|
||||
musl/getrandom.c
|
||||
musl/fcntl.c
|
||||
musl/timespec_get.c
|
||||
|
33
libs/libglibc-compatibility/musl/getentropy.c
Normal file
33
libs/libglibc-compatibility/musl/getentropy.c
Normal file
@ -0,0 +1,33 @@
|
||||
#define _DEFAULT_SOURCE
|
||||
#include <unistd.h>
|
||||
#include <sys/random.h>
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
|
||||
int getentropy(void *buffer, size_t len)
|
||||
{
|
||||
int cs, ret = 0;
|
||||
char *pos = buffer;
|
||||
|
||||
if (len > 256) {
|
||||
errno = EIO;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
|
||||
|
||||
while (len) {
|
||||
ret = getrandom(pos, len, 0);
|
||||
if (ret < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
else break;
|
||||
}
|
||||
pos += ret;
|
||||
len -= ret;
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
pthread_setcancelstate(cs, 0);
|
||||
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user