Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_dos_creatnew() create a new file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_creatnew()         Create a new file

 #include   <dos.h>

  unsigned     _dos_creatnew(path, attribute, handle);
  char *path;            String containing drive, path, and filename
  unsigned attribute;    File attributes
  int *handle;           File identifier return buffer

    _dos_creatnew uses MS-DOS function 5Bh to create a new file named
    'path' with MS-DOS file attributes specified by 'attribute'. The
    assigned handle is returned in the location pointed to by 'handle'.
    If the file already exists, _dos_creatnew() will return an error
    message. Use one or more of the following manifest constants, ORed
    together, to specify attributes.

                    Constant     Attribute
                    -------------------------------------------
                    _A_NORMAL    Normal file - full read/write
                    _A_RDONLY    Read only file
                    _A_HIDDEN    Hidden file
                    _A_SYSTEM    System file
                    _A_VOLID     Volume ID file
                    _A_SUBDIR    Subdirectory
                    _A_ARCH      Archive file

    Returns:    _dos_creatnew() returns 0 if the file was opened
                successfully. If unsuccessful it returns the MS-DOS error
                code and sets errno to one of the following manifest
                constants:

                    Constant     Meaning
                    ------------------------------------------------
                    ENOENT       Unknown path or filename

                    EMFILE       No file handles available (too
                                 many files open already)

                    EACCES       Access denied (directory is full)

                    EEXIST       File already exists

      Notes:    _dos_creatnew() opens a file with both read and write
                access, and if the MS-DOS SHARE command has been previously
                invoked the file is opened in compatibility mode.

                _dos_creatnew() is identical to _dos_creat() except that
                it only creates new files, and requires MS-DOS 3.0 or
                higher.

   Portability:     MS-DOS only, version 3.0 or higher

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

           This program creates a file using _dos_creatnew()

           #include             <dos.h>

           main()
           {
             int handle;
             unsigned err_code;

             err_code = _dos_creatnew("c:\work\datafile.dat", _A_NORMAL,
           &handle);
             if (err_code)
                printf("Unable to create file -- error code is %u\n",
           err_code);
             .
             .  (file is used and closed)
             .
           }


See Also: _dos_creat() _dos_open() _dos_close()

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