mailing list of musl libc
 help / color / mirror / code / Atom feed
d2f282ce87f04a4320a91197b138fc55501984c9 blob 496 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 
#define _BSD_SOURCE
#include <unistd.h>
#include <sys/random.h>
#include <pthread.h>
#include <errno.h>

int getentropy(void *buffer, size_t len)
{
	int cs, ret;
	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;
}
debug log:

solving d2f282ce ...
found d2f282ce in https://git.vuxu.org/mirror/musl/

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).