xref: /haiku/src/system/libroot/posix/unistd/getentropy.c (revision caed67a8cba83913b9c21ac2b06ebc6bd1cb3111)
1 /*
2  * Copyright 2023, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 #include <unistd.h>
7 
8 #include <libroot/errno_private.h>
9 #include <random_defs.h>
10 #include <syscalls.h>
11 
12 
13 int
14 getentropy(void *buf, size_t buflen)
15 {
16 	status_t status;
17 	struct random_get_entropy_args args;
18 	args.buffer = buf;
19 	args.length = buflen;
20 
21 	status = _kern_generic_syscall(RANDOM_SYSCALLS, RANDOM_GET_ENTROPY,
22 		&args, sizeof(args));
23 	if (args.length < buflen)
24 		status = EIO;
25 
26 	if (status < 0) {
27 		__set_errno(status);
28 		return -1;
29 	}
30 	return 0;
31 }
32