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++ 3.0r4 - <b>creat</b> 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, writing and execution permission after the file is closed for
   the first time. pmode takes one or both of the following values defined
   in stat.h:

           S_IREAD         read permission, owner
           S_IWRITE        write permission, owner

   When two or more constants are required, they should be joined with the
   bitwise OR operator. 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. Under MS-DOS it
   is not possible to give write-only permission, and a write-only pmode is
   ignored.

Example 

   #include <io.h>
   #include <sys\stat.h>
   #include <stdio.h>
   #include <stdlib.h>

   int main()
   {
       int fp;
       fp = creat ("file.dat", S_IREAD | S_IWRITE);
       if (fp == -1) {
           printf("Cannot create file.dat\n");
           return EXIT_FAILURE;
       }
       return EXIT_SUCCESS;
   }


Return Value

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

   EACCES           Permission to access the file or a directory on the path
                    prefix has been denied.

   EAGAIN           The specified file exists, and has a locking or sharing
                    violation.

   EMFILE           Too many open files.

   ENOENT           A path argument points to a null path name. The file or
                    path name can not be found.

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


See Also

   dos_credos_creat, close, fopen, open at, close, fopen, open


See Also: dos_credos_creat close fopen open creat close fopen open

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