import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / getentropy.c
blob4392727a956301a855abed6b223cc5f99ac25055
1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
13 * Copyright (c) 2015, Joyent, Inc.
17 * getentropy(3C) is an OpenBSD compatible wrapper around getrandom(2).
20 #include <errno.h>
21 #include <sys/random.h>
23 int
24 getentropy(void *buf, size_t buflen)
26 int ret;
28 if (buflen > 256) {
29 errno = EIO;
30 return (-1);
33 ret = getrandom(buf, buflen, 0);
34 if (ret == -1 || ret != buflen) {
35 if (errno != EFAULT)
36 errno = EIO;
37 return (-1);
40 return (0);