getentropy(3)

๐ŸŽ€ getentropy(3) โ€” bestie, let's get you some random bytes ๐Ÿ’…

okay so this is the manual page for getentropy, a lil function from the Library Functions Manual, and it is honestly one of the most wholesome functions in libc because it just... gives you randomness. like, that's the whole bit. no drama, no config, no surprises. โœจ


๐ŸŒธ NAME ๐ŸŒธ

getentropy โ€” fill a buffer with random bytes ๐ŸŽฒ

๐Ÿ“š LIBRARY ๐Ÿ“š

Standard C library (libc, -lc)

โœจ SYNOPSIS โœจ

#include <unistd.h>

int getentropy(size_t length;
               void buffer[length], size_t length);

๐ŸŒˆ Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

getentropy():
    _DEFAULT_SOURCE

yeah bestie, that's the whole secret handshake. define _DEFAULT_SOURCE and glibc will let you in. ๐Ÿซถ

๐Ÿ’– DESCRIPTION ๐Ÿ’–

The getentropy() function writes length bytes of high-quality random data to the buffer starting at the location pointed to by buffer. it's giving "cryptographically respectable, no notes" energy, fr fr. ๐Ÿ”ฅ

The maximum permitted value for the length argument is 256. that's the ceiling. do not test it. ๐Ÿ’€

A successful call to getentropy() always provides the requested number of bytes of entropy. not "maybe", not "some", not "best effort" โ€” always. periodt. ๐Ÿ‘‘

๐Ÿฆ‹ RETURN VALUE ๐Ÿฆ‹

  • On success, this function returns zero. ๐ŸŽ‰
  • On error, -1 is returned, and errno is set to indicate the error.

๐Ÿ™ˆ ERRORS ๐Ÿ™ˆ

  • EFAULT โ€” part or all of the buffer specified by buffer and length is not in valid addressable memory. girl, that memory is not there. ๐Ÿ˜ญ
  • EIO โ€” length is greater than 256. (yeah, both of the EIOs in this list are real, don't merge them, i'm watching ๐Ÿ‘€)
  • EIO โ€” an unspecified error occurred while trying to overwrite buffer with random data.
  • ENOSYS โ€” this kernel version does not implement the getrandom(2) system call required to implement this function. ancient kernel behavior honestly. ๐Ÿ’€

โญ STANDARDS โญ

POSIX.1-2024. she's standard, she's official, she's on the list. ๐Ÿ’…

๐Ÿงš HISTORY ๐Ÿงš

OpenBSD 5.6, glibc 2.25, FreeBSD 12.0, POSIX.1-2024. a whole timeline. iconic of her honestly. ๐ŸŒธ

๐Ÿ‘‘ NOTES ๐Ÿ‘‘

The getentropy() function is implemented using getrandom(2). that's the machinery under the hood, iykyk. ๐Ÿ”ง

Whereas the glibc wrapper makes getrandom(2) a cancelation point, getentropy() is not a cancelation point. write that down, bestie, it matters. ๐Ÿ“

getentropy() is also declared in <sys/random.h>. (No feature test macro need be defined to obtain the declaration from that header file.) so if you're pulling it from there, no _DEFAULT_SOURCE ritual required. โœจ

A call to getentropy() may block if the system has just booted and the kernel has not yet collected enough randomness to initialize the entropy pool. In this case, getentropy() will keep blocking even if a signal is handled, and will return only once the entropy pool has been initialized.

like... she will wait. no cap. signals cannot sway her. she returns when the vibes are ready and not one second sooner. ๐Ÿซถ

๐ŸŒŸ SEE ALSO ๐ŸŒŸ

getrandom(2), urandom(4), random(7)


and that's the page, bestie!! ๐ŸŽ€ this one came from Linux man-pages 6.20, dated 2026-04-21 โ€” so go forth, fill your buffers with exactly 256 bytes or fewer of certified premium randomness, and slay. ๐Ÿ’–๐Ÿ’…โœจ

๐Ÿ“ฆ where this page comes from
  • arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • ๐Ÿ“œ the page's license: Linux-man-pages-copyleft
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms