home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 5.ddi / CLIBSRC2.ZIP / DOSCREAT.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  4.3 KB  |  127 lines

  1. /*---------------------------------------------------------------------------
  2.  * filename - doscreat.c
  3.  *
  4.  * function(s)
  5.  *        _dos_creat     - creates a new file or rewrites an existing one
  6.  *                         (MSC compatible)
  7.  *        _dos_creatnew  - creates a new file (MSC compatible)
  8.  *--------------------------------------------------------------------------*/
  9.  
  10. /*
  11.  *      C/C++ Run Time Library - Version 5.0
  12.  *
  13.  *      Copyright (c) 1991, 1992 by Borland International
  14.  *      All Rights Reserved.
  15.  *
  16.  */
  17.  
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <_io.h>
  22.  
  23. /*--------------------------------------------------------------------------*
  24.  
  25. Name            DosCreate - create a file
  26.  
  27. Usage           local to this module
  28.  
  29. Description     used by _dos_creat and _dos_creatnew to create
  30.                 a file.
  31.  
  32. Return value    success : 0, and handle is stored at *handlep
  33.                 else    : -1 and errno is set to one of the following:
  34.  
  35.                         ENOENT   Path or file name not found
  36.                         EMFILE   Too many open files
  37.                         EACCESS  Permission denied
  38.  
  39.  
  40. *---------------------------------------------------------------------------*/
  41. static unsigned near pascal
  42. DosCreate(char *pathP, int attr, int *handlep, unsigned char func)
  43. {
  44.         pushDS_
  45. asm     mov     ah,func
  46. asm     mov     cx, attr
  47. asm     LDS_    dx, pathP
  48. asm     int     21h
  49.         popDS_
  50. asm     jc      DosCreateFailed
  51.         *handlep = _AX;
  52.         return (0);
  53.  
  54. DosCreateFailed:
  55.         return (__DOSerror(_AX));
  56. }
  57.  
  58. /*--------------------------------------------------------------------------*
  59.  
  60. Name            _dos_creat - creates a new file or rewrites an existing one.
  61.  
  62. Usage           unsigned int _creat(const char *filename, unsigned attrib,
  63.                                     int *handle );
  64.  
  65. Prototype in    dos.h
  66.  
  67. Description     _dos_creat accepts attrib, an MS-DOS attribute word.  Any
  68.                 attribute bits may be set with this call.  The file
  69.                 is always opened in binary mode.  Upon successful
  70.                 creation, the file pointer is set to the beginning
  71.                 of the file, and the file handle is copied to *handle.
  72.                 The file is opened for both reading and writing.
  73.  
  74.                 The attrib argument to _dos_creat and _dos_creatnew
  75.                 can be one of the following constants (defined in dos.h):
  76.  
  77.                         _A_RDONLY   Read only attribute
  78.                         _A_HIDDEN   Hidden file
  79.                         _A_SYSTEM   System file
  80.  
  81.                 The file handle can only be used with _dos routines;
  82.                 it cannot be used with low-level I/O routines such
  83.                 as read() or _read().
  84.  
  85. Return value    success : 0
  86.                 else    : the DOS error code, and errno is set to
  87.                           one of the following:
  88.  
  89.                         ENOENT   Path or file name not found
  90.                         EMFILE   Too many open files
  91.                         EACCESS  Permission denied
  92.  
  93. Note            Compatible with Microsoft C.  Not the same as _creat().
  94.  
  95. *---------------------------------------------------------------------------*/
  96.  
  97. unsigned _dos_creat (const char *pathP, unsigned attr, int *handle )
  98. {
  99.         return( DosCreate((char *)pathP, attr, handle, 0x3c ) );
  100. }
  101.  
  102.  
  103. /*--------------------------------------------------------------------------*
  104.  
  105. Name            _dos_creatnew - creates a new file
  106.  
  107. Usage           unsigned _dos_creatnew(char *filename, unsigned attrib,
  108.                                         unsigned *handle);
  109.  
  110. Prototype in    dos.h
  111.  
  112. Description     identical to _dos_creat, with the exception that, if
  113.                 the file exists, the creatnew call returns an
  114.                 error, leaves the file untouched, and sets errno
  115.                 to EEXIST.  Works only on DOS 3.x or later.
  116.  
  117. Return value    same as _dos_creat
  118.  
  119. Note            Compatible with Microsoft C.  Not the same as creatnew().
  120.  
  121. *---------------------------------------------------------------------------*/
  122.  
  123. unsigned _dos_creatnew (const char *pathP, unsigned attr, int *handle )
  124. {
  125.         return( DosCreate((char *)pathP, attr, handle, 0x5B ) );
  126. }
  127.