#include <fcntl.h>
|
int
creat (const char *path, mode_t mode); |
open and creat return the new file descriptor, or -1 if an error occurred(in which case, errno is set appropriately).
atime , mtime fields are set to the current time. If the file is modified because of the O_TRUNC flag, its atime , mtime fields are set to the current time.
The creat function is the same as:
open(path, O_CREAT | O_TRUNC | O_WRONLY, mode); Limitation :Creating a new file doesn’t alter the time stamp of parent directory, created entry has only two time stamps access and modification timestamps. Creation time stamp of the file is not supported, here accesstime stamp is equal to modification time stamp.
/*************************************************************************************** * Detailed description : This test code demonstrates creat system call usage, it creates a * in current working directory(if file exists then it is truncated. * * Preconditions : None ***************************************************************************************/ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main() { int fd = 0; fd = creat("Example.txt" , 0666); if(fd < 0 ) { printf("File creation failed \n"); return -1; } printf("Example.txt file created \n"); return 0; }
Output
Example.txt file created
© 2005-2007 Nokia |