F_GETFL(2const)

✨ F_GETFL, F_SETFL β€” get/set file status flags ✨

okay bestie, so this is a page from section 2const of the manual β€” literally called F_GETFL(2const). it's the whole saga of F_GETFL and F_SETFL, and honestly? it's giving "tiny page, huge power". let's get into it πŸ’…


πŸŽ€ NAME πŸŽ€

F_GETFL, F_SETFL β€” get/set file status flags


πŸ“š LIBRARY πŸ“š

Standard C library (libc, link it with -lc)


πŸ¦‹ SYNOPSIS πŸ¦‹

#include <fcntl.h>

int fcntl(int fd, F_GETFL);
int fcntl(int fd, F_SETFL, int arg);

πŸ’– DESCRIPTION πŸ’–

So every single open file description has its own little set of status flags, right? They get initialized by open(2) and then possibly modified later by fcntl(2). The important part β€” the main character energy part β€” is this: when you duplicate a file descriptor (with dup(2), F_DUPFD(2const), fork(2), etc.), all those copies point at the same open file description, which means they all share the same file status flags. One fd changes them, they all feel it. friendship bracelets basically 🫢

The file status flags themselves and what they actually mean are described over in open(2).

  • F_GETFL β€” returns the file access mode and the file status flags, as the function result. arg is ignored, she's just there, she doesn't need to speak πŸ’€
  • F_SETFL β€” sets the file status flags to whatever value arg says. But bestie, listen: the file access mode (O_RDONLY, O_WRONLY, O_RDWR) and the file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) that show up in arg are ignored. On Linux, this operation can only change the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags. And you genuinely cannot change the O_DSYNC and O_SYNC flags β€” see BUGS, below. no cap 😭

πŸ‘‘ RETURN VALUE πŸ‘‘

  • F_GETFL β€” the value of the file status flags.
  • F_SETFL β€” zero.

And if something goes wrong: -1 gets returned, and errno is set to tell you what the error is. so dramatic πŸ’€


πŸ™ˆ ERRORS πŸ™ˆ

See fcntl(2).

  • EPERM β€” you tried to clear the O_APPEND flag on a file that has the append-only attribute set. nope. not allowed. the file said no 🌸

⭐ STANDARDS ⭐

POSIX.1-2024.


🌈 HISTORY 🌈

SVr4, 4.3BSD, POSIX.1-1988. ancient icons fr fr.


πŸ’€ BUGS πŸ’€

F_SETFL

It is not possible to use F_SETFL to change the state of the O_DSYNC and O_SYNC flags. And here's the unhinged part β€” attempts to change the state of these flags are silently ignored. no error, no warning, just vibes and nothing happening πŸ™ˆ


πŸ”₯ SEE ALSO πŸ”₯

fcntl(2), open(2)


okay that's the whole page!! mwah πŸ’– this was from Linux man-pages 6.20, dated 2026-01-05 β€” so if you're reading this, shoutout to the man-pages girlies, they ate πŸŽ€βœ¨

πŸ“¦ 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