text
stringlengths
0
234
source
(i.e., the same source as the
.ir /dev/random
device)
instead of the
.i urandom
source.
the
.i random
source is limited based on the entropy that can be obtained from environmental
noise.
if the number of available bytes in the
.i random
source is less than requested in
.ir buflen ,
the call returns just the available random bytes.
if no random bytes are available, the behavior depends on the presence of
.b grnd_nonblock
in the
.i flags
argument.
.tp
.b grnd_nonblock
by default, when reading from the
.ir random
source,
.br getrandom ()
blocks if no random bytes are available,
and when reading from the
.ir urandom
source, it blocks if the entropy pool has not yet been initialized.
if the
.b grnd_nonblock
flag is set, then
.br getrandom ()
does not block in these cases, but instead immediately returns \-1 with
.i errno
set to
.br eagain .
.sh return value
on success,
.br getrandom ()
returns the number of bytes that were copied to the buffer
.ir buf .
this may be less than the number of bytes requested via
.i buflen
if either
.br grnd_random
was specified in
.ir flags
and insufficient entropy was present in the
.ir random
source or the system call was interrupted by a signal.
.pp
on error, \-1 is returned, and
.i errno
is set to indicate the error.
.sh errors
.tp
.b eagain
the requested entropy was not available, and
.br getrandom ()
would have blocked if the
.b grnd_nonblock
flag was not set.
.tp
.b efault
the address referred to by
.i buf
is outside the accessible address space.
.tp
.b eintr
the call was interrupted by a signal
handler; see the description of how interrupted
.br read (2)
calls on "slow" devices are handled with and without the
.b sa_restart
flag in the
.br signal (7)
man page.
.tp
.b einval
an invalid flag was specified in
.ir flags .
.tp
.b enosys
the glibc wrapper function for
.br getrandom ()
determined that the underlying kernel does not implement this system call.
.sh versions
.br getrandom ()
was introduced in version 3.17 of the linux kernel.
support was added to glibc in version 2.25.
.sh conforming to
this system call is linux-specific.
.sh notes
for an overview and comparison of the various interfaces that
can be used to obtain randomness, see
.br random (7).
.pp