CLOSEFROM(2)

πŸ’… CLOSEFROM β€” the closefrom and close_range system calls, bestie

okay so you know how file descriptors just... pile up?? like laundry but for your process?? yeah. this is the manual page for closefrom and close_range, and it's giving "spring cleaning but make it syscalls" 🧹✨


πŸ¦‹ NAME

closefrom, close_range β€” delete open file descriptors

no cap, that's literally the whole job. they delete open file descriptors. slay.


πŸ“š LIBRARY

Standard C Library (libc, -lc)


✨ SYNOPSIS

#include <unistd.h>

void
closefrom(int lowfd);

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

🌸 DESCRIPTION

okay so first up: the closefrom() system call 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. and here's the chaotic part β€” any errors encountered while closing file descriptors are ignored. like, it does NOT care. it's just closing things and moving on with its life πŸ™ˆ

then we got close_range(), which is the glow-up version. it deletes all open file descriptors between lowfd and highfd inclusive, clamped to the range of open file descriptors. same energy as before: any errors encountered while closing file descriptors are ignored. and listen β€” there are currently no defined flags. zero. none. the flags slot is empty, it's a vibe check that nobody has passed yet πŸ’€


🫢 RETURN VALUES

when it eats, it eats: 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. so check your errno bestie, it's telling you something 😭


πŸŽ€ ERRORS

the close_range() system call will fail if:

  • [EINVAL] β€” the highfd argument is lower than the lowfd argument. girl. that's backwards. that range is invalid 🚫
  • [EINVAL] β€” an invalid flag was set. (remember, there are currently no defined flags, so like... what are you even setting πŸ‘€)

πŸ‘‘ SEE ALSO


🌈 HISTORY

the closefrom() function first appeared in FreeBSD 8.0. a legend was born, periodt πŸ’œ


and that's the whole page, bestie!! this one came from the <strong>Debian</strong> manual pages, dated <strong>April 12, 2020</strong>, and it's filed under <strong>CLOSEFROM(2)</strong> πŸŽ€ go close some file descriptors, you got this πŸ’–

πŸ“¦ where this page comes from