int creat(path, mode) char *path; int mode;
#include <sys/stat.h>
int creat(path, mode) char *path; mode_t mode;
This interface is made obsolete by open.2v since,
creat(path, mode);
is equivalent to
open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
creat() creates a new ordinary file or prepares to rewrite an existing file named by the pathname pointed to by path. If the file did not exist, it is given the mode mode, as modified by the process's mode mask (see umask.2v See stat.2v for the construction of mode.
If the file exists, its mode and owner remain unchanged, but it is truncated to 0 length. Otherwise, the file's owner ID is set to the effective user ID of the process, and upon successful completion, creat() marks for update the st_atime, st_ctime, and st_mtime fields of the file (see stat.2v and the st_ctime and st_mtime fields of the parent directory.
The file's group ID is set to either:
The low-order 12 bits of the file mode are set to the value of mode, modified as follows:
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 execve.2v system calls. See fcntl.2v
If the file did not previously exist, upon successful completion, creat() marks for update the st_ctime and st_mtime fields of the file and the st_ctime and st_mtime fields of the parent directory.
creat() returns a non-negative descriptor that only permits writing on success. On failure, it returns -1 and sets errno to indicate the error.
The file referred to by path does not exist and the directory in which it is to be created is not writable.
The file referred to by path exists, but it is unwritable.
The user's quota of inodes on the file system on which the file is being created has been exhausted.
A pathname component is longer than {NAME_MAX} while {_POSIX_NO_TRUNC} is in effect (see pathconf.2v
There are no free inodes on the file system on which the file is being created.
In addition to the above, the following may also occur:
The 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 O_EXCL open mode, or flock.2 facility.
Created by unroff & hp-tools. © somebody (See intro for details). All Rights Reserved. Last modified 11/5/97