mailing list of musl libc
 help / color / mirror / code / Atom feed
964b8c10a30feb550829e2a7186511e32e853dbb blob 526 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
34
35
36
 
#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;
	}

	pthread_setcancelstate(cs, 0);

	if (len) {
		errno = EIO;
		return -1;
	}
	return 0;
}
debug log:

solving 964b8c10 ...
found 964b8c10 in https://inbox.vuxu.org/musl/20220409225851.715796-1-Jason@zx2c4.com/
found 651ea95f in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 651ea95f14310cda867b88378a0aedf2225d4462	src/misc/getentropy.c

applying [1/1] https://inbox.vuxu.org/musl/20220409225851.715796-1-Jason@zx2c4.com/
diff --git a/src/misc/getentropy.c b/src/misc/getentropy.c
index 651ea95f..964b8c10 100644

warning: core.fsyncObjectFiles is deprecated; use core.fsync instead
Checking patch src/misc/getentropy.c...
Applied patch src/misc/getentropy.c cleanly.

index at:
100644 964b8c10a30feb550829e2a7186511e32e853dbb	src/misc/getentropy.c

Code repositories for project(s) associated with this 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).