Manual Page Result
0
Command: open | Section: 2 | Source: UNIX v10 | File: open.2
OPEN(2) System Calls Manual OPEN(2)
NAME
open, creat, close - open a file for reading or writing, create file
SYNOPSIS
int open(file, rwmode)
char *file;
int creat(file, mode)
char *file;
int close(fildes)
DESCRIPTION
Open opens the file, for reading if rwmode is 0, for writing if rwmode
is 1, or for both if rwmode is 2, and returns an associated file de-
scriptor. File is a null-terminated string representing a path name.
The file pointer is set to 0.
Creat creates a new file or prepares to rewrite an existing file, opens
it for writing, and returns an associated file descriptor. If the file
is new, the owner is set to the effective userid of the creating
process; the group to that of the containing directory; the mode to
mode as modified by the mode mask of the creating process; see
umask(2). Mode need not allow writing. If the file already exists, it
is truncated to 0 length; the mode, owner, and group remain unchanged,
and must permit writing.
A program may reserve a filename for exclusive use by calling creat
with a mode that forbids writing. If the file does not exist, creat
will succeed; further attempts to creat the same file will be denied.
More sophisticated (but less portable) concurrent access control may be
obtained by setting the S_ICCTYP field in the mode; see stat(2).
Close closes the file associated with a file descriptor. Files are
closed upon termination of a process, but since there is a limit on the
number of open files per process, close is necessary for programs which
deal with many files. It is possible to arrange for files to be closed
by exec(2); see FIOCLEX in ioctl(2).
SEE ALSO
dup(2), pipe(2), read(2), exec(2), ioctl(2), stat(2), unlink(2)
DIAGNOSTICS
open, creat: EACCES, EBUSY, ECONC, EFAULT, EINTR, EIO, EISDIR, ELOOP,
EMFILE, ENFILE, ENOENT, ENOTDIR, EROFS, ETXTBSY
creat: ENOSPC
close: EBADF
BUGS
It should be possible to call open without waiting for carrier on com-
munication lines.
The group of a newly-created file should (once again) be the effective
groupid of the creating process.
The trick of creating a file with an unwritable mode fails for the su-
per-user.
OPEN(2)