creat()
PROTOTYPE
#include <posix.h>
int creat(const char *path, mode_t mode);
DESCRIPTION
If the file specified by path exists, creat() truncates it to zero length and opens it in write-only mode. Paths starting with ‘/’ are absolute. Otherwise they are relative to the CWD. The file’s status change and data modification timestamps are updated.
Otherwise, creat() creates a new regular file at the specified location. Every timestamp of the new file and the status change and data modification timestamps of the parent directory are updated. As modified by the file mode creation mask, mode sets the file’s access permission bits. Its user and group IDs are set to those of the calling task (as determined by FsGetId()).
creat(path, mode) is equivalent to open(path, O_WRONLY | O_CREAT | O_TRUNC, mode).
The caller needs search access to the path prefix and either write access to the parent directory if the file is new or write access to the file if it exists.
If successful, creat() returns a file descriptor, a small integer used by other API routines to reference the file. Otherwise, it sets errno and returns -1.
ERROR CODES
| EACCES | No search access to the path prefix, write access denied if file exists, or no parent directory write access if file is new. |
| EFAULT | path equals NULL. |
| EINVAL | The new leaf name or the value of mode is invalid. |
| EISDIR | The specified file is a directory. |
| EMFILE | No file control block is free. FOPEN_MAX files are currently open. |
| ENAMETOOLONG | A name in path exceeds the effective maximum file name length. |
| ENOENT | path is the empty string or includes a directory that was not found. |
| ENOSPC | No space is left on volume to create file. |
| ENOTDIR | One of the non-leaf path components is not a directory. |
| EROFS | The volume is read-only. |
EXAMPLE
fid = creat("foo", 0666);