Name

creat - creates a file or device

Library

libc.lib

Synopsis

  #include <fcntl.h>
  int creat (const char *path, mode_t mode);

Return values

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.


Detailed description

This interface is made obsolete by:
open

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.

         


Examples

/***************************************************************************************
* 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

         


See also

open

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top