fcntl(2)

๐Ÿ’… fcntl โ€” manipulate file descriptor

okay bestie, pull up a chair ๐ŸŽ€ this is <fcntl.h>, the header you include before you get to play. and yes, the manual calls this thing fcntl(2) โ€” a system call, not a library page, so jot that down. it lives in the Standard C library (libc, link with -lc). we're doing file descriptor manipulation today and honestly? she ate. ๐Ÿ”ฅ


โœจ SYNOPSIS โœจ

#include <fcntl.h>

int fcntl(int fd, int op, ...);

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so <pink>fcntl()does **one of the operations described below** on the open file descriptorfd. which one? that's literally what opis for, bestie.op` picks the operation. periodt. ๐Ÿ‘‘

now real talk โ€” some of these operations only exist since a particular Linux kernel version. and the preferred way to check whether your host kernel even supports a particular operation? you just call fcntl() with the op value you want, and then test whether the call failed with EINVAL โ€” because EINVAL means the kernel doesn't recognize this value. that's the vibe check. ๐Ÿซถ

๐Ÿฆ‹ Duplicating a file descriptor

๐Ÿฆ‹ File descriptor flags

๐Ÿฆ‹ File status flags

๐Ÿฆ‹ Advisory record locking

๐Ÿฆ‹ Open file description locks (non-POSIX)

๐Ÿฆ‹ Managing signals

๐Ÿฆ‹ Leases

๐Ÿฆ‹ Delegations

๐Ÿฆ‹ File and directory change notification (dnotify)

๐Ÿฆ‹ Changing the capacity of a pipe

๐Ÿฆ‹ File Sealing

๐Ÿฆ‹ File read/write hints


๐Ÿ’– RETURN VALUE ๐Ÿ’–

good news: on success, the return value depends on the operation. it's giving โœจsituationalโœจ. no single answer, sorry bestie.

bad news: on error, -1 is returned, and errno is set to indicate the error. ๐Ÿ˜ญ


๐Ÿ’€ ERRORS ๐Ÿ’€

  • EACCES or EAGAIN โ€” Operation is prohibited by locks held by other processes. somebody else is holding the lock, and it is not your turn. ๐Ÿ™ˆ
  • EAGAIN โ€” The operation is prohibited because the file has been memory-mapped by another process.
  • EBADF โ€” fd is not an open file descriptor. ma'am. that's not a real fd. ๐Ÿ’€
  • EINVAL โ€” The value specified in op is not recognized by this kernel.

๐ŸŒˆ VERSIONS ๐ŸŒˆ

POSIX.1-2024 specifies FD_CLOFORK and F_DUPFD_CLOFORK, but Linux doesn't support them. not us, not our house, we don't have those. ๐Ÿ™…โ™€๏ธ


โญ STANDARDS โญ

POSIX.1-2024. iykyk. ๐Ÿ’…


๐ŸŽ€ HISTORY ๐ŸŽ€

4.3BSD, SVr4, POSIX.1-1988. she's got lore. she's been around. iconic behavior honestly. ๐Ÿซถ


๐Ÿ‘‘ SEE ALSO ๐Ÿ‘‘


ok that's the whole page bestie, all 40-ish of those F_* operations, every flag, every error, every standard, nothing skipped, no cap. go forth and manipulate some file descriptors responsibly. ๐ŸŒธ๐Ÿ’–

and before you go โ€” this lil masterpiece is from the Linux man-pages 6.20, dated 2026-02-08. 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