creat - open and possibly create a file or device
#include <sys/types.h> /* for mode_t / #include <sys/stat.h> / for the S_* contants / #include <fcntl.h> / for creat() prototype */ int creat(const char *pathname, mode_t mode);
creat(2) is a special form of open(2), refer to open(2) for more information.
The creat(2) system call is used to convert a pathname into a file descriptor (a small, non-negative integer for use in subsequent I/O as with read(2), write(2), etc.). When the call is successful, the file descriptor returned will be the lowest file descriptor not currently open for the process. This call creates a new open file, not shared with any other process. (But shared open files may arise via the fork(2) system call.) The new file descriptor is set to remain open across exec functions (see fcntl(2)). The file offset is set to the beginning of the file.
creat(2) is equivalent to open(2) with flags equal to O_CREAT|O_WRONLY|O_TRUNC.
Since creat(2) doesn't take any flags, any additional flags you may wish to pass, can be modified using fcntl(2) instead.
The argument mode specifies the permissions to use in case a new file is created. It is modified by the process's umask in the usual way: the permissions of the created file are (mode & umask).
The following symbolic constants are provided for mode:
|S_IRWXU|00700| user (file owner) has read, write and execute permission |S_IRUSR (S_IREAD)|00400| user has read permission |S_IWUSR (S_IWRITE)|00200| user has write permission |S_IXUSR (S_IEXEC)|00100| user has execute permission |S_IRWXG|00070| group has read, write and execute permission |S_IRGRP|00040| group has read permission |S_IWGRP|00020| group has write permission |S_IXGRP|00010| group has execute permission |S_IRWXO|00007| others have read, write and execute permission |S_IROTH|00004| others have read permission |S_IWOTH|00002| others have write permisson |S_IXOTH|00001| others have execute permission
creat(2) returns the new file descriptor, or -1 if an error occurred (in which case, errno is set appropriately). Note that while open(2) can open device special files, but creat(2) cannot create them - use mknod(2) instead.
If the file is newly created, its atime, ctime, mtime fields are set to the current time, and so are the ctime and mtime fields of the parent directory. Otherwise, if the file is modified because of the O_TRUNC flag, its ctime and mtime fields are set to the current time.
SVr4, SVID, POSIX, X/OPEN, BSD 4.3
read(2), write(2), fcntl(2), close(2), link(2), mknod(2), mount(2), stat(2), umask(2), unlink(2), socket(2), fopen(3), fifo(4)