Declaration:
int creat(char path[], int amode);
Description
Creates a new file or overwrites an existing one.
Note. Remember that the backslash in a path requires '\\'.
creat creates a new file or prepares to rewrite an existing file given by path. amode applies only to newly created files. A file created with creat is always created in the translation mode specified by the _fmode global variable (O_TEXT or O_BINARY). If the file exists and the write attribute is set, then creat will truncate the file to the length of 0 bytes, leaving the file attributes unchanged. If the existing file has the read-only attribute set, then the creat call will fail and the file will remain unchanged. The creat call examines only the S_IWRITE bit of the access-mode word amode. If this bit is 1, then the file can be written to. If the bit is 0, then the file is marked as read-only. All other operating system attributes are set to 0. amode can be one of the following (defined in system.h):
Value of amode Access permission
S_IWRITE Permission to write
S_IREAD Permission to read
S_IREAD | S_IWRITE Permission to read and write (write permission
implies read permission))
Returned value
Upon successful completion, creat returns the new file handle (a nonnegative integer); otherwise, it returns -1. In the event of error, the errno global variable is set to one of the following:
EACCES Permission denied
ENOENT Path or file name not found
EMFILE Too many open files
|