The file name specified by
for either execution or reading and/or writing as specified by the
and the file descriptor returned to the calling process.
argument may indicate the file is to be
created if it does not exist (by specifying the
In this case
require an additional argument
and the file is created with mode
as described in
and modified by the process umask value (see
function is equivalent to the
function except in the case where the
specifies a relative path.
In this case the file to be opened is determined relative to the directory
associated with the file descriptor
instead of the current working directory.
parameter and the optional fourth parameter correspond exactly to
the parameters of
is passed the special value
parameter, the current working directory is used
and the behavior is identical to a call to
The flags specified are formed by
the following values
O_RDONLY open for reading only
O_WRONLY open for writing only
O_RDWR open for reading and writing
O_EXEC open for execute only
O_NONBLOCK do not block on open
O_APPEND append on each write
O_CREAT create file if it does not exist
O_TRUNC truncate size to 0
O_EXCL error if create and file exists
O_SHLOCK atomically obtain a shared lock
O_EXLOCK atomically obtain an exclusive lock
O_DIRECT eliminate or reduce cache effects
O_FSYNC synchronous writes
O_SYNC synchronous writes
O_NOFOLLOW do not follow symlinks
O_DIRECTORY error if file is not a directory
O_CLOEXEC set FD_CLOEXEC upon open
Opening a file with
set causes each write on the file
to be appended to the end.
is specified and the
file exists, the file is truncated to zero length.
is set with
and the file already
returns an error.
This may be used to
implement a simple exclusive access locking mechanism.
is set and the last component of the pathname is
a symbolic link,
will fail even if the symbolic
link points to a non-existent name.
flag is specified and the
system call would result
in the process being blocked for some reason (e.g., waiting for
carrier on a dialup line),
The descriptor remains in non-blocking mode for subsequent operations.
is used in the mask, all writes will
immediately be written to disk,
the kernel will not cache written data
and all writes on the descriptor will not return until
the data to be written completes.
is a synonym for
is used in the mask and the target file passed to
is a symbolic link then the
When opening a file, a lock with
semantics can be obtained by setting
for a shared lock, or
for an exclusive lock.
If creating a file with
the request for the lock will never fail
(provided that the underlying file system supports locking).
may be used to minimize or eliminate the cache effects of reading and writing.
The system will attempt to avoid caching the data you read or write.
If it cannot avoid caching the data,
it will minimize the impact the data has on the cache.
Use of this flag can drastically reduce performance if not used with care.
may be used to ensure the OS does not assign this file as the
controlling terminal when it opens a tty device.
This is the default on
but is present for
system call will not assign controlling terminals on
may be used to ensure the OS restores the terminal attributes when
initially opening a TTY.
This is the default on
but is present for
The initial call to
on a TTY will always restore default terminal attributes on
may be used to ensure the resulting file descriptor refers to a
This flag can be used to prevent applications with elevated privileges
from opening files which are even unsafe to open with
such as device nodes.
may be used to set
flag for the newly returned file descriptor.
returns a non-negative integer, termed a file descriptor.
It returns -1 on failure.
The file pointer used to mark the current position within the
file is set to the beginning of the file.
If a sleeping open of a device node from
is interrupted by a signal, the call always fails with
even if the
flag is set for the signal.
A sleeping open of a fifo (see
is restarted as normal.
When a new file is created it is given the group of the directory
which contains it.
flag was specified,
the new descriptor is set to remain open across
system calls; see
The system imposes a limit on the number of file descriptors
open simultaneously by one process.
system call returns the current system limit.