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 regular file or prepares to rewrite an existing file named by the path name pointed to by path.
If the file exists, its length is truncated to 0, and its mode and owner are unchanged. Otherwise, the file’s owner ID is set to the effective user ID of the process. If the set-group-ID bit of the parent directory is set, the directory’s group ID is set to the group ID of the parent directory. Otherwise, the directory’s group ID is set to the process’s effective group ID. 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 are cleared. See chmod(2).
Upon successful completion, the file descriptor is returned and the file is open for writing (only), even if the mode does not permit writing. The file offset is set to the beginning of the file. The file descriptor is set to remain open across exec system calls (see fcntl(2)). No process can have more than OPEN_MAX files open simultaneously. This is discussed in open(2). A new file can be created with a mode that forbids writing.
Access Control Lists (ACLs)
On systems that support access control lists, three base ACL entries are created corresponding to the file access permission bits. An existing file’s access control list is unchanged by creat (see setacl(2), chmod(2), and acl(5)).
ERRORS
Creat fails if one or more of the following is true:
[ENOSPC] Not enough space on the file system.
[ENOTDIR] A component of the path prefix is not a directory.
[ENOENT] The named file does not exist (for example, path is null, or a component of path does not exist).
[EACCES] Search permission is denied on a component of the path prefix.
[EACCES] The file does not exist and the directory in which the file is to be created does not permit writing.
[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.
[EACCES] The file exists and write permission is denied.
[EISDIR] The named file is an existing directory.
[EMFILE] More than the maximum number of file descriptors are currently open.
[EFAULT] Path points outside the allocated address space of the process. The reliable detection of this error is implementation dependent.
[ENFILE] The system file table is full.
[ENXIO] The named file is a character special or block special file, and the device associated with this special file does not exist.
[ENAMETOOLONG]
The length of the specified path name exceeds PATH_MAX bytes, or the length of a component of the path name exceeds NAME_MAX bytes while _POSIX_NO_TRUNC is in effect.
[EAGAIN] The file exists, enforcement mode file and record locking is set and there are outstanding record locks on the file.
[ELOOP] Too many symbolic links were encountered in translating the path name.
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), lockf(2), lseek(2), open(2), read(2), setacl(2), truncate(2), umask(2), write(2), acl(5).
STANDARDS CONFORMANCE
creat: SVID2, XPG2, XPG3, POSIX.1, FIPS 151-1
Hewlett-Packard Company — HP-UX Release 7.0: Sept 1989