#include <fcntl.h>
int open(path, flags[ , mode ] ) char *path; int flags; int mode;
#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h>
int open(path, flags[ , mode ] ) char *path; int flags; mode_t mode;
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 set:
An open() for reading-only returns without delay. An open() for writing-only returns an error if no process currently has the file open for reading.
If O_NDELAY is clear:
A call to open() for reading-only blocks until a process opens the file for writing. A call to open() for writing-only blocks until a process opens the file for reading.
When opening a file associated with a communication line:
If O_NDELAY is set:
A call to open() returns without waiting for carrier.
If O_NDELAY is clear:
A call to open() blocks until carrier is present.
The low-order 12 bits of the file mode are set to the value of mode, modified as follows (see creat.2v
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.
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
open()
returns
a non-negative file descriptor
on success.
On failure,
it returns
-1
and sets
errno
to indicate the error.
The file referred to by path does not exist, O_CREAT is specified, and the directory in which it is to be created does not permit writing.
O_TRUNC is specified and write permission is denied for the file named by path.
The required permissions (for reading and/or writing) are denied for the file named by path.
The file does not exist, O_CREAT is specified, and the user's quota of inodes on the file system on which the file is being created has been exhausted.
An I/O error occurred while reading from or writing to the file system.
A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf.2v
A component of the path prefix of path does not exist.
The file does not exist, O_CREAT is specified, and there are no free inodes on the file system on which the file is being created.
The file is a character special or block special file, and the associated device does not exist.
O_NONBLOCK is set, the named file is a FIFO, O_WRONLY 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 the file is to be opened for writing.
In addition to the above, the following may also occur:
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97