open.2 (2010 09)

o
open(2) open(2)
NAME
open() - open file for reading or writing
SYNOPSIS
#include <fcntl.h>
int open(const char *path, int oflag, ... /*
[mode_t mode] */ );
Remarks
The ANSI C ", ..." construct specifies a variable length argument list whose optional member is given
in the associated comment (/* */
).
DESCRIPTION
The
open() system call opens a le descriptor for the named file and sets the file status flags according
to the value of oflag.
The path argument points to a path name naming a file, and must not exceed
PATH_MAX bytes in length.
The oflag argument is a value that is the bitwise inclusive OR of flags listed in "Read-Write Flags," "Gen-
eral Flags," "Synchronized I/O Flags," and "Direct I/O Flags" below.
The optional mode argument is only effective when the
O_CREAT flag is specified.
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).
Read-Write Flags
Exactly one of the
O_RDONLY, O_WRONLY,orO_RDWR flags must be used in composing the value of
oflag. If none or more than one is used, the behavior is undefined.
O_RDONLY Open for reading only.
O_WRONLY Open for writing only.
O_RDWR Open for reading and writing.
General Flags
Several of the flags listed below can be changed with the
fcntl() system call while the file is open. See
fcntl (2) and fcntl (5) for details.
O_APPEND If set, the file offset is set to the end of the file prior to each write.
O_CREAT If the file exists, this flag has no effect, except as noted under
O_EXCL below. Oth-
erwise, the owner 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 if the set-group-ID
bit of the parent directory is not set, or to the group ID of the parent directory if the
set-group-ID bit of the parent directory is set.
The file access permission bits of the new file mode are set to the value of mode,
modified as follows (see creat (2)):
For each bit set in the file mode creation mask of the process, the corresponding
bit in the new file mode is cleared (see umask(2)).
The "save text image after execution" bit of the new file mode is cleared. See
chmod(2).
On HFS file systems with access control lists, three base ACL entries are created
corresponding to the file access permissions (see acl (5)).
On JFS file systems that support access control lists, optional ACL entries are
created corresponding to the parent directory’s default ACL entries (see aclv (5)).
O_EXCL If O_EXCL and O_CREAT are set and the file exists, open() fails.
O_LARGEFILE
This is a non-standard flag which may be used by 32-bit applications to access files
larger than 2 GB. See creat64 (2).
O_NDELAY This flag might affect subsequent reads and writes. See read (2) and write(2).
HP-UX 11i Version 3: September 2010 1 Hewlett-Packard Company 1

Summary of content (4 pages)