getentropy() — Fill a buffer with random bytes

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both  

Format

#define _XPLATFORM_SOURCE            
#include <unistd.h>

int getentropy(void *buffer, size_t length);

General description

getentropy() function writes length bytes of high-quality random data to the buffer that starts at the location that is pointed to by buffer. The maximum valid value for the length argument is 256.

Returned value

If successful, getentropy() returns 0.

If unsuccessful, getentropy() returns -1 and sets errno to one of the following values:
Error Code
Description
EFAULT
Part or all of the buffer that is specified by buffer and length is not in valid addressable memory.
EIO
length is greater than 256.

Related information