Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>_creat() create a new file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _creat()                Create a New File

 #include   <io.h>

 int        _creat(filename,attrib);
 const char *filename                    Name of new file
 int        attrib;                      Attribute word

    _creat() either creates a new file or opens an existing file
    specified by 'filename' and truncates it to zero length for
    rewriting.  If successfully opened, the file pointer is set to the
    beginning of the file. If the file is new, it is created in the
    translation mode (O_TEXT or O_BINARY) specified by the global
    variable '_fmode'.  A file can be created in a particular mode by
    assigning a value to '_fmode' or by calling open() with the O_CREAT
    and O_TRUNC option ORed with the desired translation mode.

    _creat() accepts the MS-DOS attribute word 'attrib'.  'attrib' must
    be one of the following constants (defined in <dos.h>):

                FA_RDONLY     Read only attribute
                FA_HIDDEN     Hidden file
                FA_SYSTEM     System file

       Returns:     If successful, returns the new file handle, a non-
                    negative integer.  On error, -1 is returned and
                    'errno' (defined in <errno.h>) is set to one of the
                    following:

                      ENOENT       Path or file name not found
                      EMFILE       Too many open files
                      EACCES       Permission denied

   Portability:     MS-DOS only.

   -------------------------------- Example ---------------------------------

    The following statements create a hidden file named "secret".

           #include <stdio.h>      /* for printf */
           #include <dos.h>     /* for 'FA_HIDDEN */
           #include <io.h>         /* for _creat */

           main()
           {
               int handle;

               handle = _creat("secret",FA_HIDDEN);
               if (handle == -1)
                   printf("couldn't create SECRET");
               else
                   printf("SECRET file created");
           }


See Also: creat() creatnew() creattemp()

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