creat()

NAME

creat() - create a new file

SYNOPSIS

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

int creat (const char *path, mode_t mode)

DESCRIPTION

The creat(2) call opens a file for writing. If the file doesn't exist, it is created with the permissions specified by mode; the owner and group IDs are set from the calling process's effective user and group IDs.

If the file does exist, it's truncated to zero length. The owner and group IDs aren't changed.

The creat(2) function is the same as:

open(path, O_CREAT | O_TRUNC | O_WRONLY, mode);

RETURN VALUES

On success, the creat(2) call returns an integer file descriptor which refers to the file. On failure, the call returns -1 and sets errno

ERRORS

The named file is opened unless:

[EACCES]
Search permission is denied for a component of the path prefix.
[EACCES]
The required permissions (for reading and/or writing) are denied for the given flags.
[EACCES]
The file does not exist and the directory in which it is to be created does not permit writing.
[EEXIST]
O_CREAT and O_EXCL were specified and the file exists.
[EINTR]
The creat(2) operation was interrupted by a signal.
[EIO]
An I/O error occurred while making the directory entry or allocating the file serial number for O_CREAT.
[EISDIR]
The named file is a directory, and the arguments specify it is to be opened for writing.
[ELOOP]
Too many symbolic links were encountered in translating the pathname.
[EMFILE]
The process has already reached its limit for open file descriptors.
[ENAMETOOLONG]
A component of a pathname exceeded {NAME_MAX} characters, or an entire pathname exceeded {PATH_MAX} characters.
[ENFILE]
The system file table is full.
[ENOENT]
O_CREAT was not specified and the named file does not exist.
[ENOENT]
A component of the pathname that must exist does not exist.
[ENOSPC]
The file does not exist and 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.
[ENOSPC]
O_CREAT is specified, the file does not exist, and there are no free file serial numbers on the file system on which the file is being created.
[ENOTDIR]
A component of the path prefix is not a directory.
[ENXIO]
The named file is a character special or block special file, and the device associated with this special file does not exist.
[EROFS]
The named file resides on a read-only file system, and the file is to be modified.

SEE ALSO

open(2)

close(2)