未验证 提交 45f3c5d5 编写于 作者: A alexey-milovidov 提交者: GitHub

Merge pull request #4825 from proller/fix24

Add libglibc-compatibility/musl/getentropy.c
......@@ -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
......
#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;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册