home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / CREAT.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  2.7 KB  |  96 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. /*|                                                              |*/
  11. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  12. /*|                                                              |*/
  13. /*|                                                              |*/
  14. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  15. /*|     All Rights Reserved.                                     |*/
  16. /*|                                                              |*/
  17. /*[]------------------------------------------------------------[]*/
  18.  
  19. #pragma inline
  20. #include <asmrules.h>
  21. #include <io.h>
  22. #include <_io.h>
  23. #include <sys\stat.h>
  24. #include <fcntl.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 creat(const char *path, register int mode)
  80. {
  81.     register int    fd;
  82.  
  83.     mode &= _notUmask;
  84.     fd = dosCreat (path, (mode & S_IWRITE) ? 0 : 1);
  85.  
  86.     if (fd >= 0)
  87.     {
  88.            _exitopen = _xclose;
  89.     _openfd [fd] = _fmode | O_RDWR | O_CHANGED |
  90.  
  91.        ((ioctl (fd, 0) & 0x80) ? O_DEVICE : 0);
  92.     }
  93.  
  94.     return fd;
  95. }
  96.