OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) NAME NAME NAME NAME open - open for reading or writing SYNOPSIS SYNOPSIS SYNOPSIS SYNOPSIS #include int open (path, oflag[, mode]) char *path; int oflag, mode; DESCRIPTION DESCRIPTION DESCRIPTION DESCRIPTION Path points to a path name naming a file. Open opens a file descriptor for the named file and sets the file status flags according to the value of oflag . Oflag values are constructed by or-ing flags from the following list (only one of the first three flags below may be used): O_RDONLY Open for reading only. O_WRONLY Open for writing only. O_RDWR Open for reading and writing. O_NDELAY This flag may affect subsequent reads and writes. See read (2) and write (2). When opening a FIFO with O_RDONLY or O_WRONLY set: If O_NDELAY is set: An open for reading-only will return without delay. An open for writing-only will return an error if no process currently has the file open for reading. If O_NDELAY is clear: An open for reading-only will block until a process opens the file for writing. An open for writing-only will block until a process opens the file for reading. When opening a file associated with a communication line: If O_NDELAY is set: The open will return without waiting for carrier. If O_NDELAY is clear: The open will block until carrier is present. Hewlett-Packard - 1 - (printed 12/12/84) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) O_APPEND If set, the file pointer will be set to the end of the file prior to each write. O_CREAT If the file exists, this flag has no effect. Otherwise, the file's owner ID is set to the process's effective user ID, the file's group ID is set to the process's effective group ID, and the low-order 12 bits of the file mode are set to the value of mode modified as follows (see creat (2)): All bits set in the process's file mode creation mask are cleared. See umask (2). The ``save text image after execution bit'' of the mode is cleared. See chmod (2). O_TRUNC If the file exists, its length is truncated to 0 and the mode and owner are unchanged. O_EXCL If O_EXCL and O_CREAT are set, open will fail if the file exists. Upon successful completion a non-negative integer, the file descriptor, is returned. 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. See fcntl (2). No process may have more than 20 file descriptors open simultaneously. The named file is opened unless one or more of the following are true: A component of the path prefix is not a directory. [ENOTDIR] O_CREAT is not set and the named file does not exist. [ENOENT] A component of the path prefix denies search permission. [EACCES] Oflag permission is denied for the named file. [EACCES] The named file is a directory and oflag is write or read/write. [EISDIR] Hewlett-Packard - 2 - (printed 12/12/84) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) OPEN(2) HP Integral PC OPEN(2) The named file resides on a read-only file system and oflag is write or read/write. [EROFS] Twenty (20) file descriptors are currently open. [EMFILE] The named file is a character special or block special file, and the device associated with this special file does not exist. [ENXIO] The file is a pure procedure (shared text) file that is being executed and oflag is write or read/write. [ETXTBSY] Path points outside the process's allocated address space. [EFAULT] O_CREAT and O_EXCL are set, and the named file exists. [EEXIST] O_NDELAY is set, the named file is a FIFO, O_WRONLY is set, and no process has the file open for reading. [ENXIO] RETURN VALUE RETURN VALUE RETURN VALUE RETURN VALUE Upon successful completion, a non-negative integer, namely a file descriptor, is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. DIAGNOSTICS DIAGNOSTICS DIAGNOSTICS DIAGNOSTICS A file does not exist on the physical media on which it is to reside until a close is performed. SEE ALSO SEE ALSO SEE ALSO SEE ALSO close(2), creat(2), dup(2), fcntl(2), lseek(2), read(2), write(2). Hewlett-Packard - 3 - (printed 12/12/84)