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

  1. /*---------------------------------------------------------------------------
  2.  * filename - creat.cas
  3.  *
  4.  * function(s)
  5.  *        dosCreat - Create or truncate a file
  6.  *        creat - creates a new file or rewrites an existing one
  7.  *--------------------------------------------------------------------------*/
  8.  
  9. /*
  10.  *      C/C++ Run Time Library - Version 5.0
  11.  *
  12.  *      Copyright (c) 1987, 1992 by Borland International
  13.  *      All Rights Reserved.
  14.  *
  15.  */
  16.  
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <io.h>
  21. #include <_io.h>
  22. #include <sys\stat.h>
  23. #include <fcntl.h>
  24. #include <RtlData.h>
  25.  
  26. extern  void    (*_exitopen)();
  27. extern  void    _xclose();
  28.  
  29. extern  unsigned _notUmask;
  30.  
  31.  
  32. /*--------------------------------------------------------------------------*
  33.  
  34. Name            dosCreat - Create or truncate a file
  35.  
  36. Description     interface to interrupt 0x21 function 0x3C - Create or
  37.                 truncate file.
  38.  
  39. Return          success : the file handle
  40.                 else : -1
  41.  
  42. *---------------------------------------------------------------------------*/
  43. static int pascal near dosCreat(const char *pathP, unsigned attrib)
  44. {
  45.         pushDS_
  46. asm     LDS_    dx, pathP
  47. asm     mov     ah, 3Ch
  48. asm     mov     cx, attrib
  49. asm     int     21h             /* AX = creat (DS:DX, CX)       */
  50.         popDS_
  51. asm     jc      dosCreatFailed
  52.         return _AX;
  53.  
  54. dosCreatFailed:
  55.         return  __IOerror (_AX);
  56. }
  57.  
  58.  
  59. /*--------------------------------------------------------------------------*
  60.  
  61. Name            creat - creates a new file or rewrites an existing one
  62.  
  63. Usage           int creat(const char *filename, int permiss);
  64.  
  65. Prototype in    io.h
  66.  
  67. Description     creates a new file or prepares to rewrite an existing
  68.                 file named by the string pointed to by filename. permiss
  69.                 only applies to newly created files.
  70.  
  71. Return value    success : the new file handle
  72.                 else : -1 and errno is set to one of the following:
  73.  
  74.                         ENOENT  Path or file name not found
  75.                         EMFILE  Too many open files
  76.                         EACCESS Permission denied
  77.  
  78. *---------------------------------------------------------------------------*/
  79. int _CType _FARFUNC creat(const char *path, register int mode)
  80. {
  81.     register int    fd;
  82.     _QRTLDataBlock;
  83.  
  84.     mode &= _QRTLInstanceData(_notUmask);
  85.     fd = dosCreat (path, (mode & S_IWRITE) ? 0 : 1);
  86.  
  87.     if (fd >= 0)
  88.     {
  89.         _exitopen = _xclose;
  90.         _QRTLInstanceData(_openfd) [fd] =
  91.             _QRTLInstanceData(_fmode) | O_RDWR | O_CHANGED |
  92.             ((ioctl (fd, 0) & 0x80) ? O_DEVICE : 0) |
  93.             (mode & S_IWRITE ? _O_WRITABLE : 0);
  94.     }
  95.  
  96.     return fd;
  97. }
  98.