1The open() system call opens the file specified by pathname. If the
2specified file does not exist, it may optionally (if O_CREAT is
3specified in flags) be created by open().
4
5The return value of open() is a file descriptor, a small, nonnegative
6integer that is used in subsequent system calls (read(2), write(2),
7lseek(2), fcntl(2), etc.) to refer to the open file. The file
8descriptor returned by a successful call will be the lowest-numbered
9file descriptor not currently open for the process.
10
11By default, the new file descriptor is set to remain open across an
12execve(2) (i.e., the FD_CLOEXEC file descriptor flag described in
13fcntl(2) is initially disabled); the O_CLOEXEC flag, described below,
14can be used to change this default. The file offset is set to the
15beginning of the file (see lseek(2)).
16
17A call to open() creates a new open file description, an entry in the
18system-wide table of open files. The open file description records
19the file offset and the file status flags (see below). A file
20descriptor is a reference to an open file description; this reference
21is unaffected if pathname is subsequently removed or modified to
22refer to a different file. For further details on open file
23descriptions, see NOTES.
24
25The argument flags must include one of the following access modes:
26O_RDONLY, O_WRONLY, or O_RDWR. These request opening the file read-
27only, write-only, or read/write, respectively.
28
29In addition, zero or more file creation flags and file status flags
30can be bitwise-or'd in flags. The file creation flags are O_CLOEXEC,
31O_CREAT, O_DIRECTORY, O_EXCL, O_NOCTTY, O_NOFOLLOW, O_TMPFILE, and
32O_TRUNC. The file status flags are all of the remaining flags listed
33below. The distinction between these two groups of flags is that the
34file creation flags affect the semantics of the open operation
35itself, while the file status flags affect the semantics of
36subsequent I/O operations. The file status flags can be retrieved
37and (in some cases) modified; see fcntl(2) for details.