CLOSEFROM(2)

πŸ“¦
version 15.1 Β· 2 versions
, in freebsd 15.1

✨ NAME ✨

closefrom, close_range β€” delete open file descriptors πŸ’…

okay so bestie, this is the manual page for closefrom(2) and close_range(2) β€” they're literally the "bye bye file descriptors" girlies πŸ‘‹βœ¨


πŸŽ€ LIBRARY πŸŽ€

Standard C Library (libc, -lc) β€” she lives there, no cap 🫢


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <unistd.h>

void
closefrom(int lowfd);

int
close_range(u_int lowfd, u_int highfd, int flags);

🌸 DESCRIPTION 🌸

Okay so first up: closefrom() is a system call that deletes all open file descriptors greater than or equal to lowfd from the per-process object reference table. That's it, that's the whole vibe ✨ any errors encountered while closing file descriptors are ignored β€” she's unbothered, she's thriving, she does not care πŸ’…

Then we have close_range(), which deletes all open file descriptors between lowfd and highfd inclusive, clamped to the range of open file descriptors. Same energy: any errors encountered while closing file descriptors are ignored, periodt 😌

The supported flags are:

  • CLOSE_RANGE_CLOEXEC β€” set the close-on-exec flag on descriptors in the range instead of closing them πŸ”₯
  • CLOSE_RANGE_CLOFORK β€” set the close-on-fork flag on descriptors in the range instead of closing them 🌈

⭐ RETURN VALUES ⭐

Upon successful completion, close_range() returns a value of 0. Otherwise, a value of -1 is returned and the global variable errno is set to indicate the error. (Yes bestie, <italic>errno</italic> is literally the main character of error reporting πŸŽ€)


πŸ’€ ERRORS πŸ’€

The close_range() system call will fail if:

  • [EINVAL] β€” the highfd argument is lower than the lowfd argument. not her getting the order wrong 😭
  • [EINVAL] β€” an invalid flag was set. nope, not on the list, not today πŸ™ˆ

πŸ’– SEE ALSO πŸ’–

  • close(2) β€” the og, the blueprint, we stan πŸ‘‘

🧚 HISTORY 🧚

  • The closefrom() function first appeared in FreeBSD 8.0.
  • The close_range() function first appeared in FreeBSD 12.2.
  • The CLOSE_RANGE_CLOFORK flag appeared in FreeBSD 15.0.

okay that's the whole page bestie, hope it slayed πŸ’… this little drop came from the Debian fam, dated October 27, 2025 β€” mwah, take care, and remember: close your fds before they close you 🫢✨

πŸ“¦ where this page comes from
  • freebsd 15.1: base 15.1
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms