| OPEN(2V) | 21 January 1990 | OPEN(2V) |
| NAME |
| open - open or create a file for reading or writing |
| SYNOPSIS |
|
|
| SYSTEM |
|
|
| DESCRIPTION |
|
path points to the pathname of a file. open() opens the named file for reading and/or writing, as specified by the flags argument, and returns a descriptor for that file. The flags argument may indicate the file is to be created if it does not already exist (by specifying the O_CREAT flag), in which case the file is created with mode mode as described in chmod(2V) and modified by the process' umask value (see umask(2V)). If the path is an empty string, the kernel maps this empty pathname to the current directory. flags values are constructed by ORing flags from the following list (one and only one of the first three flags below must be used):
If O_NDELAY is clear: When opening a file associated with a communication line: If O_NDELAY is set: If O_NDELAY is clear:
The seek pointer used to mark the current position within the file is set to the beginning of the file. The new descriptor is set to remain open across execve(2V) system calls; see close(2V) and fcntl(2V). There is a system enforced limit on the number of open file descriptors per process, whose value is returned by the getdtablesize(2) call. If O_CREAT is set and the file did not previously exist, upon successful completion, open() marks for update the st_atime, st_ctime, and st_mtime fields of the file and the st_ctime and st_mtime fields of the parent directory. If O_TRUNC is set and the file previously existed, upon successful completion, open() marks for update the st_ctime and st_mtime fields of the file. |
| SYSTEM |
|
If path points to an empty string an error results. The flags above behave as described, with the following exception: If the O_NDELAY or O_NONBLOCK flag is set on a call to open(), the corresponding flag is set for that file descriptor (see fcntl(2V)) and subsequent reads and writes to that descriptor will not block (see read(2V) and write(2V)). |
| RETURN |
|
open()
returns
a non-negative file descriptor
on success.
On failure,
it returns
-1
and sets
errno
to indicate the error.
|
| ERRORS |
|
| SYSTEM |
|
In addition to the above, the following may also occur:
|
| SEE |
| chmod(2V), close(2V), creat(2V), dup(2V), fcntl(2V), getdtablesize(2), getmsg(2), lseek(2V), mknod(2V), mount(2V), putmsg(2), read(2V), umask(2V) write(2V) |
| OPEN(2V) | 21 January 1990 | OPEN(2V) |