Files
seta75D ff309bfe1c Init
2021-10-11 18:37:13 -03:00

277 lines
5.4 KiB
Plaintext

.\" @(#)creat.2v 1.1 94/10/31 SMI; from UCB 4.3
.\" Copyright (c) 1980 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\"
.TH CREAT 2V "21 January 1990"
.SH NAME
creat \- create a new file
.SH SYNOPSIS
.LP
.nf
.ft B
int creat(path, mode)
char *path;
int mode;
.ft R
.fi
.SH SYSTEM V SYNOPSIS
.LP
.nf
.ft B
#include <sys/stat.h>
.ft
.fi
.LP
.nf
.ft B
int creat(path, mode)
char *path;
mode_t mode;
.ft R
.fi
.IX creat() "" \fLcreat()\fP
.IX file "create new"
.SH DESCRIPTION
.LP
This interface is made obsolete by
.BR open (2V),
since,
.IP
.B creat(path, mode);
.LP
is equivalent to
.IP
.B "open(path, \s-1O_WRONLY\s0 | \s-1O_CREAT\\s0 | \s-1O_TRUNC\s0, mode);"
.LP
.B creat(\|)
creates a new ordinary file or prepares to rewrite an existing file
named by the pathname pointed to by
.IR path .
If the file did not exist, it is given the mode
.IR mode ,
as modified by the process's mode mask (see
.BR umask (2V)).
See
.BR stat (2V)
for the construction of
.IR mode .
.LP
If the file exists, its mode and owner remain unchanged,
but it is truncated to 0 length.
Otherwise, the file's owner
.SM ID
is set to the effective user
.SM ID
of the process, and upon successful completion,
.B creat(\|)
marks for update the
.BR st_atime ,
.BR st_ctime ,
and
.B st_mtime
fields of the file
(see
.BR stat (2V))
and the
.B st_ctime
and
.B st_mtime
fields of the parent directory.
.LP
The file's group
.SM ID
is set to either:
.TP 3
\(bu
the effective group
.SM ID
of the process, if the filesystem was not
mounted with the
.SM BSD
file-creation semantics flag (see
.BR mount (2V))
and the set-gid bit of the parent directory is clear, or
.TP 3
\(bu
the group
.SM ID
of the directory in which the file is created.
.LP
The low-order 12 bits of the file mode are set to the value of
.IR mode ,
modified as follows:
.TP 3
\(bu
All bits set in the process's file mode creation mask are cleared.
See
.BR umask (2V).
.TP 3
\(bu
The \*(lqsave text image after execution\*(rq (sticky) bit of the mode is
cleared. See
.BR chmod (2V).
.TP 3
\(bu
The \*(lqset group
.SM ID
on execution\*(rq bit of the mode is cleared if the
effective user
.SM ID
of the process is not super-user and the process
is not a member of the group of the created file.
.LP
Upon successful completion, the file descriptor
is returned and the file is open for writing,
even if the access permissions of the file mode do not permit writing.
The file pointer is set to the beginning of the file.
The file descriptor is set to remain open across
.BR execve (2V)
system calls. See
.BR fcntl (2V).
.LP
If the file did not previously exist, upon successful
completion,
.B creat(\|)
marks for update the
.B st_ctime
and
.B st_mtime
fields of the file and the
.B st_ctime
and
.B st_mtime
fields of the parent directory.
.SH RETURN VALUES
.LP
.B creat(\|)
returns
a non-negative descriptor that only permits writing
on success.
On failure,
it returns
\-1
and sets
.B errno
to indicate the error.
.SH ERRORS
.TP 20
.SM EACCES
Search permission is denied for a component of the path prefix.
.IP
The file referred to by
.I path
does not exist and the directory
in which it is to be created is not writable.
.IP
The file referred to by
.I path
exists, but it is unwritable.
.TP
.SM EDQUOT
The directory in which the entry for the new file
is being placed cannot be extended because the
user's quota of disk blocks on the file system
containing the directory has been exhausted.
.IP
The user's quota of inodes on the file system on
which the file is being created has been exhausted.
.TP
.SM EFAULT
.I path
points outside the process's allocated address space.
.TP
.SM EINTR
The
.B creat(\|)
operation was interrupted by a signal.
.TP
.SM EIO
An I/O error occurred while making the directory entry
or allocating the inode.
.TP
.SM EISDIR
The file referred to by
.I path
is a directory.
.TP
.SM ELOOP
Too many symbolic links were encountered in translating
the pathname pointed to by
.IR path .
.TP
.SM EMFILE
There are already too many files open.
.TP
.SM ENAMETOOLONG
The length of the path argument exceeds
.SM {PATH_MAX}\s0.
.IP
A pathname component is longer than
.SM {NAME_MAX}
while
.SM {_POSIX_NO_TRUNC}
is in effect
(see
.BR pathconf (2V)).
.TP
.SM ENFILE
The system file table is full.
.TP
.SM ENOENT
A component of the path prefix
does not exist.
.TP
.SM ENOSPC
The directory in which the entry for the new file
is being placed cannot be extended because there is
no space left on the file system containing the directory.
.IP
There are no free inodes on the file system on which
the file is being created.
.TP
.SM ENOTDIR
A component of the path prefix
is not a directory.
.TP
.SM ENXIO
The file is a character special or block special file, and
the associated device does not exist.
.TP
.SM EOPNOTSUPP
The file was a socket (not currently implemented).
.TP
.SM EROFS
The file referred to by
.I path
resides, or would reside, on a read-only file system.
.SH SYSTEM V ERRORS
.LP
In addition to the above, the following may also occur:
.TP 20
.SM ENOENT
.I path
points to an empty string.
.SH "SEE ALSO"
.BR close (2V),
.BR chmod (2V),
.BR execve (2V),
.BR fcntl (2V),
.BR flock (2),
.BR mount (2V),
.BR open (2V),
.BR write (2V),
.BR umask (2V)
.SH NOTES
.LP
The
.I mode
given is arbitrary; it need not allow writing.
This feature has been used in the past by
programs to construct a simple exclusive locking
mechanism. It is replaced by the
.SB O_EXCL
open mode, or
.BR flock (2)
facility.