---
name: "fcntl.h"
section: "0p"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/fcntl.h"
---

# fcntl.h(0p)

file control options

## PROLOG

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page for details of Linux behavior), or the interface may not be implemented on Linux.

## NAME

fcntl.h — file control options

## SYNOPSIS

```
#include <fcntl.h>
```

## DESCRIPTION

The *\<fcntl.h\>* header shall define the following symbolic constants for the *cmd* argument used by *fcntl*(). The values shall be unique and shall be suitable for use in **#if** preprocessing directives.

- F\_DUPFD

  Duplicate file descriptor.

- F\_DUPFD\_CLOEXEC

  Duplicate file descriptor with the close-on-*exec* flag FD\_CLOEXEC set.

- F\_GETFD

  Get file descriptor flags.

- F\_SETFD

  Set file descriptor flags.

- F\_GETFL

  Get file status flags and file access modes.

- F\_SETFL

  Set file status flags.

- F\_GETLK

  Get record locking information.

- F\_SETLK

  Set record locking information.

- F\_SETLKW

  Set record locking information; wait if blocked.

- F\_GETOWN

  Get process or process group ID to receive SIGURG signals.

- F\_SETOWN

  Set process or process group ID to receive SIGURG signals.

The *\<fcntl.h\>* header shall define the following symbolic constant used for the *fcntl*() file descriptor flags, which shall be suitable for use in **#if** preprocessing directives.

- FD\_CLOEXEC

  Close the file descriptor upon execution of an *exec* family function.

The *\<fcntl.h\>* header shall also define the following symbolic constants for the *l\_type* argument used for record locking with *fcntl*(). The values shall be unique and shall be suitable for use in **#if** preprocessing directives.

- F\_RDLCK

  Shared or read lock.

- F\_UNLCK

  Unlock.

- F\_WRLCK

  Exclusive or write lock.

The *\<fcntl.h\>* header shall define the values used for *l\_whence*, SEEK\_SET, SEEK\_CUR, and SEEK\_END as described in *\<stdio.h\>*.

The *\<fcntl.h\>* header shall define the following symbolic constants as file creation flags for use in the *oflag* value to *open*() and *openat*(). The values shall be bitwise-distinct and shall be suitable for use in **#if** preprocessing directives.

- O\_CLOEXEC

  The FD\_CLOEXEC flag associated with the new descriptor shall be set to close the file descriptor upon execution of an *exec* family function.

- O\_CREAT

  Create file if it does not exist.

- O\_DIRECTORY

  Fail if file is a non-directory file.

- O\_EXCL

  Exclusive use flag.

- O\_NOCTTY

  Do not assign controlling terminal.

- O\_NOFOLLOW

  Do not follow symbolic links.

- O\_TRUNC

  Truncate flag.

- O\_TTY\_INIT

  Set the **termios** structure terminal parameters to a state that provides conforming behavior; see *Section 11.2*, *Parameters that Can be Set*.

The O\_TTY\_INIT flag can have the value zero and in this case it need not be bitwise-distinct from the other flags.

The *\<fcntl.h\>* header shall define the following symbolic constants for use as file status flags for *open*(), *openat*(), and *fcntl*(). The values shall be suitable for use in **#if** preprocessing directives.

- O\_APPEND

  Set append mode.

- O\_DSYNC

  Write according to synchronized I/O data integrity completion.

- O\_NONBLOCK

  Non-blocking mode.

- O\_RSYNC

  Synchronized read I/O operations.

- O\_SYNC

  Write according to synchronized I/O file integrity completion.

The *\<fcntl.h\>* header shall define the following symbolic constant for use as the mask for file access modes. The value shall be suitable for use in **#if** preprocessing directives.

- O\_ACCMODE

  Mask for file access modes.

The *\<fcntl.h\>* header shall define the following symbolic constants for use as the file access modes for *open*(), *openat*(), and *fcntl*(). The values shall be unique, except that O\_EXEC and O\_SEARCH may have equal values. The values shall be suitable for use in **#if** preprocessing directives.

- O\_EXEC

  Open for execute only (non-directory files). The result is unspecified if this flag is applied to a directory.

- O\_RDONLY

  Open for reading only.

- O\_RDWR

  Open for reading and writing.

- O\_SEARCH

  Open directory for search only. The result is unspecified if this flag is applied to a non-directory file.

- O\_WRONLY

  Open for writing only.

The *\<fcntl.h\>* header shall define the symbolic constants for file modes for use as values of **mode\_t** as described in *\<sys/stat.h\>*.

The *\<fcntl.h\>* header shall define the following symbolic constant as a special value used in place of a file descriptor for the *\*at*() functions which take a directory file descriptor as a parameter:

- AT\_FDCWD

  Use the current working directory to determine the target of relative file paths.

The *\<fcntl.h\>* header shall define the following symbolic constant as a value for the *flag* used by *faccessat*():

- AT\_EACCESS

  Check access using effective user and group ID.

The *\<fcntl.h\>* header shall define the following symbolic constant as a value for the *flag* used by *fstatat*(), *fchmodat*(), *fchownat*(), and *utimensat*():

- AT\_SYMLINK\_NOFOLLOW

  Do not follow symbolic links.

The *\<fcntl.h\>* header shall define the following symbolic constant as a value for the flag used by *linkat*():

- AT\_SYMLINK\_FOLLOW

  Follow symbolic link.\

The *\<fcntl.h\>* header shall define the following symbolic constant as a value for the flag used by *unlinkat*():

- AT\_REMOVEDIR

  Remove directory instead of file.

The *\<fcntl.h\>* header shall define the following symbolic constants for the *advice* argument used by *posix\_fadvise*():

- POSIX\_FADV\_DONTNEED

  The application expects that it will not access the specified data in the near future.

- POSIX\_FADV\_NOREUSE

  The application expects to access the specified data once and then not reuse it thereafter.

- POSIX\_FADV\_NORMAL

  The application has no advice to give on its behavior with respect to the specified data. It is the default characteristic if no advice is given for an open file.

- POSIX\_FADV\_RANDOM

  The application expects to access the specified data in a random order.

- POSIX\_FADV\_SEQUENTIAL

  The application expects to access the specified data sequentially from lower offsets to higher offsets.

- POSIX\_FADV\_WILLNEED

  The application expects to access the specified data in the near future.

The *\<fcntl.h\>* header shall define the **flock** structure describing a file lock. It shall include the following members:

```
short  l_type   Type of lock; F_RDLCK, F_WRLCK, F_UNLCK.
short  l_whence Flag for starting offset.
off_t  l_start  Relative offset in bytes.
off_t  l_len    Size; if 0 then until EOF.
pid_t  l_pid    Process ID of the process holding the lock; returned with F_GETLK.
```

The *\<fcntl.h\>* header shall define the **mode\_t**, **off\_t**, and **pid\_t** types as described in *\<sys/types.h\>*.

The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.

```
int  creat(const char *, mode_t);
int  fcntl(int, int, ...);
int  open(const char *, int, ...);
int  openat(int, const char *, int, ...);
int  posix_fadvise(int, off_t, off_t, int);
int  posix_fallocate(int, off_t, off_t);
```

Inclusion of the *\<fcntl.h\>* header may also make visible all symbols from *\<sys/stat.h\>* and *\<unistd.h\>*.

*The following sections are informative.*

## APPLICATION USAGE

Although no existing implementation defines AT\_SYMLINK\_FOLLOW and AT\_SYMLINK\_NOFOLLOW as the same numeric value, POSIX.1‐2008 does not prohibit that as the two constants are not used with the same interfaces.

## RATIONALE

While many of the symbolic constants introduced in the *\<fcntl.h\>* header do not strictly need to be used in **#if** preprocessor directives, widespread historic practice has defined them as macros that are usable in such constructs, and examination of existing applications has shown that they are occasionally used in such a way. Therefore it was decided to retain this requirement on an implementation in POSIX.1‐2008.

## FUTURE DIRECTIONS

None.

## SEE ALSO

***\<stdio.h\>***, ***\<sys\_stat.h\>***, ***\<sys\_types.h\>***, ***\<unistd.h\>***

The System Interfaces volume of POSIX.1‐2017, *creat()*, *exec*, *fcntl()*, *futimens()*, *open()*, *posix\_fadvise()*, *posix\_fallocate()*, *posix\_madvise()*

## COPYRIGHT

Portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .

Any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting\_bugs.html .
