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.argis ignored, she's just there, she doesn't need to speak πF_SETFLβ sets the file status flags to whatever valueargsays. 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 inargare ignored. On Linux, this operation can only change theO_APPEND,O_ASYNC,O_DIRECT,O_NOATIME, andO_NONBLOCKflags. And you genuinely cannot change theO_DSYNCandO_SYNCflags β 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 theO_APPENDflag 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 π₯
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