Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - creat http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   creat

   Usage
   #include <io.h>
   #include <sys\stat.h>
   int creat(char *name, int pmode);

   Description
   The  system  call  creat()  either creates a new  file  or  opens  and
   truncates  an existing file. The permission setting, pmode,  sets  the
   new file's reading and writing permission after the file is closed for
   the  first  time.  pmode takes one or both  of  the  following  values
   defined in stat.h:

   #define S_IREAD 0000400/* read permission, owner */
   #define S_IWRITE 0000200/* write permission, owner */

   When  both  constants  are required, they should be  joined  with  the
   bitwise OR operator. Under MSDOS it is not possible to give write only
   permission, so a write-only pmode is currently ignored. Write-only  is
   provided  for compatibility. Note that creat will open the  file  with
   read/write  permission regardless of the setting of pmode.  The  pmode
   will  only  take effect after the file has been closed for  the  first
   time.

   Example
   #include <io.h>
   #include <sys\stat.h>
   main()
   {
   int fp;
        fp = creat ("file.dat", S_IREAD | S_IWRITE);
        if(fp == -1)
        printf("Cannot create file.dat\n");
   }

   Return Value
   creat  returns a -1 if an error occurred and sets errno to one of  the
   following (defined in errno.h):

   ENOENT    No such file or directory.
   EMFILE    Too many open files.
   EACCES    Permission denied.

   creat will return with an error and errno set to EACCESS if an attempt
   is made to truncate an existing file with read-only permission.
   In  a similar way to chdir(), close(), etc., creat returns  an  MS-DOS
   file handle if the file was created.


See Also: dos_creat close fopen open

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson