creat(2)
NAME
creat − create a new file or rewrite an existing one
SYNOPSIS
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int creat (path, mode)
char ∗path;
mode_t mode;
DESCRIPTION
creat creates a new ordinary file or prepares to rewrite an existing file named by the path name pointed to by path.
If the file exists, the length is truncated to 0 and the mode and owner are unchanged. Otherwise, the file’s owner ID is set to the effective user ID of the process, the file’s group ID is set to the effective group ID of the process, and the low-order 12 bits of the file mode are set to the value of mode modified as follows:
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).
Upon successful completion, the file descriptor is returned and the file is open for writing, even if the mode does not permit writing. The file pointer is set to the beginning of the file. The file descriptor is set to remain open across ecec system calls. See fcntl(2). A process may not have more files descriptors open at a time, than specified by its current limit for open file descriptors. A new file may be created with a mode that forbids writing.
creat will fail if one or more of the following are true:
[EACCES] Search permission is denied on a component of the path prefix, or the file does not exist and the directory in which the file is to be created does not permit writing, or the file exists and write permission is denied.
[EAGAIN] If the file exists with enforced record locking enabled (see chmod(2)) and there are record locks on the file.
[EFAULT] Path points outside the allocated address space of the process.
[EISDIR] The named file is an existing directory.
[EMFILE] The process has too many open files (see sysconf(2) or getrlimit(2)).
[ENAMETOOLONG] The path argument exceeds {PATH_MAX} in length, or a pathname component is longer than {NAME_MAX} (see pathconf(2)).
[ENFILE] The system file table or system inode table is full.
[ENOENT] A component of the path prefix does not exist, or the path argument points to an empty string.
[ENOTDIR] A component of the path prefix is not a directory.
[ENXIO] The file is a character special or block special file, and the associated device does not exist.
[EROFS] The named file resides or would reside on a read-only file system.
[ETXTBSY] The file is a pure procedure (shared text) file that is being executed.
RETURN VALUE
Upon successful completion, a non-negative integer, namely the file descriptor, is returned. Otherwise, a value of −1 is returned and errno is set to indicate the error.
SEE ALSO
chmod(2), close(2), dup(2), fcntl(2), lseek(2), open(2), read(2), umask(2), write(2), getrlimit(2).
CX/UX Programmer’s Reference Manual