open for reading or writing
cc . . . -lc
int open (const char *path, int oflag, ... );
path points to a path name naming a file.
The open system call
opens a file descriptor for the named file
and sets the file status flags
according to the value of
For non-STREAMS files, oflag
values are constructed by OR-ing flags
from the following list (only one of the first three flags below
can be used):
Open for reading only.
Open for writing only.
Open for reading and writing.
If set, the file pointer is set to the end of the file
prior to each write.
If the file exists, this flag has no effect.
Otherwise, the user ID of the file
is set to the effective user ID
of the process;
the group ID of the file
is set to the effective group ID
of the process or to the group ID of the file's parent directory;
the low-order 12 bits of the file mode are set to the value of
mode, modified as follows (see
All bits set in the file mode creation mask of the process are cleared
The ``save text image after execution bit'' of the mode is cleared
Causes open to fail if the file exists. This can only be used
if O_CREAT is also set.
If this flag is set and path identifies a terminal, then that
terminal is prevented from becoming the controlling terminal for the process
When opening a regular file, this flag affects subsequent writes.
If set, each
waits for both the file data and file status to be physically updated.
If the file exists, is a regular file, and is opened for writing, its length
is truncated to 0. The mode, owner and group are left unchanged. It has no
effect on FIFO special files or directories.
This flag may affect subsequent reads and writes
When opening a FIFO with O_RDONLY or
If O_NONBLOCK is set:
for reading only returns without delay.
for writing only returns an error if no process
currently has the file open for reading.
If O_NONBLOCK is not set:
for reading only will block until a process
opens the file for writing.
for writing only blocks until a process
opens the file for reading.
When opening a file associated with a communication line:
If O_NONBLOCK is set:
The open returns without waiting for carrier.
If O_NONBLOCK is not set:
The open blocks until carrier is present.
When opening a STREAMS file,
may be constructed from O_NONBLOCK or-ed with either
O_RDONLY, O_WRONLY or O_RDWR. Other flag
values are not applicable to STREAMS devices and have no
effect on them. The value of O_NONBLOCK affects the
operation of STREAMS drivers and certain system calls (see
For drivers, the implementation of
O_NONBLOCK is device-specific. Each STREAMS device
driver may treat this option differently.
Certain flag values can be set following open as described
The file pointer used to mark the current position within the file
is set to the beginning of the file.
The new file descriptor is set to remain open across
exec system calls
The named file is opened unless one or more of the following is true:
A component of the
denies search permission.
permission is denied for the named file.
The file does not exist and write permission is not set for the parent
directory of the file to be created.
O_TRUNC is specified and write permission is not set for the file.
The file exists, mandatory file/record locking is set,
and there are outstanding record locks on the file (see
and O_TRUNC is included in oflag.
O_CREAT and O_EXCL
are set, and the named file exists.
path points outside the allocated address space of the process.
A signal was caught during the
open system call.
The value of oflag is not valid.
A hangup or error occurred during a STREAMS
The named file is a directory and
oflag includes O_WRONLY or O_RDWR
OPEN_MAX descriptors are open in the current process.
Components of path require hopping to
multiple remote machines.
The length of path exceeds PATH_MAX or the length of
a pathname component exceeds NAME_MAX while
_POSIX_NO_TRUNC is in effect.
The system file table is full, SYS_OPEN files are open in the
is not set and the named file does not exist.
O_CREAT is set and either the path prefix does
not exist or the path argument is a null string.
path points to a remote machine, and the link
to that machine is no longer active.
The system is unable to allocate a send descriptor.
are set, and the file system is out of inodes.
Unable to allocate a stream.
A component of the path prefix
is not a directory.
The named file is a character special or block special file,
and the device associated with this special file does not exist.
is set, the named file is a
is set, and no process has the file open for reading.
A STREAMS module or driver open routine failed.
The named file resides on a read-only file system and
oflag includes either O_WRONLY, O_RDWR,
O_CREAT (if the file does not exist) or O_TRUNC.
The file is a pure procedure (shared text) file that is being executed and
oflag includes either O_WRONLY or O_RDWR.
A maximum of three XENIX or UNIX partitions may be opened
on a hard disk.
Even if any of these are subsequently closed, no more may be
opened until reboot.
Upon successful completion,
the file descriptor
Otherwise, a value of -1 is returned, and
errno is set to indicate the error.
open is conformant with:
X/Open Portability Guide, Issue 3, 1989
Intel386 Binary Compatibility Specification, Edition 2 (iBCSe2)
IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1)
NIST FIPS 151-1
© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005