F_GETFL(2const) F_GETFL(2const)

F_GETFL, F_SETFL - get/set file status flags

Standard C library (libc-lc)

#include <fcntl.h>
int fcntl(int fd, F_GETFL);
int fcntl(int fd, F_SETFL, int arg);

Each open file description has certain associated status flags, initialized by open(2) and possibly modified by fcntl(2). Duplicated file descriptors (made with dup(2), F_DUPFD(2const), fork(2), etc.) refer to the same open file description, and thus share the same file status flags.

The file status flags and their semantics are described in open(2).

Return (as the function result) the file access mode and the file status flags; arg is ignored.
Set the file status flags to the value specified by arg. File access mode (O_RDONLY, O_WRONLY, O_RDWR) and file creation flags (i.e., O_CREAT, O_EXCL, O_NOCTTY, O_TRUNC) in arg are ignored. On Linux, this operation can change only the O_APPEND, O_ASYNC, O_DIRECT, O_NOATIME, and O_NONBLOCK flags. It is not possible to change the O_DSYNC and O_SYNC flags; see BUGS, below.

Value of file status flags.
Zero.

On error, -1 is returned, and errno is set to indicate the error.

See fcntl(2).

Attempted to clear the O_APPEND flag on a file that has the append-only attribute set.

POSIX.1-2008.

SVr4, 4.3BSD, POSIX.1-2001.

It is not possible to use F_SETFL to change the state of the O_DSYNC and O_SYNC flags. Attempts to change the state of these flags are silently ignored.

fcntl(2), open(2)

2025-07-20 Linux man-pages 6.15