home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 2.ddi / CLIB2.ZIP / OPENA.CAS < prev    next >
Encoding:
Text File  |  1990-06-07  |  1.8 KB  |  66 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - opena.cas
  3.  *
  4.  * function(s)
  5.  *        _open - opens a file for reading or writing
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*[]------------------------------------------------------------[]*/
  9. /*|                                                              |*/
  10. /*|     Turbo C Run Time Library - Version 3.0                   |*/
  11. /*|                                                              |*/
  12. /*|                                                              |*/
  13. /*|     Copyright (c) 1987,1988,1990 by Borland International    |*/
  14. /*|     All Rights Reserved.                                     |*/
  15. /*|                                                              |*/
  16. /*[]------------------------------------------------------------[]*/
  17.  
  18. #pragma inline
  19. #include <asmrules.h>
  20. #include <io.h>
  21. #include <fcntl.h>
  22. #include <_io.h>
  23.  
  24. /*-----------------------------------------------------------------------*
  25.  
  26. Name        _open - opens a file for reading or writing
  27.  
  28. Usage        #include <fcntl.h>
  29.         int _open(const char *pathname, int access);
  30.  
  31. Prototype in    io.h
  32.  
  33. Description    see open
  34.  
  35. *------------------------------------------------------------------------*/
  36. int _CType _open( const char *filename, int oflag )
  37. {
  38.     register int        fd;
  39.  
  40. asm        mov        al, 1
  41. asm        mov        cx, oflag
  42. asm        test    cx, O_WRONLY
  43. asm        jnz        ready
  44. asm        mov        al, 2
  45. asm        test    cx, O_RDWR
  46. asm        jnz        ready
  47. asm        mov        al, 0
  48. ready:
  49.         pushDS_
  50. asm        LDS_    dx, filename
  51. asm        mov        cl, 0F0h
  52. asm        and        cl, oflag
  53. asm        or        al, cl
  54. asm        mov        ah, 3Dh
  55. asm        int        21h        /* AX = sopen (DS:DX, AL) */
  56.         popDS_
  57. asm        jc        _openFailed
  58.  
  59. asm        mov        fd,ax
  60.         _openfd[fd] = (oflag & ~_O_RUNFLAGS) | O_BINARY;
  61.         return(fd);
  62.  
  63. _openFailed:
  64.         return __IOerror (_AX);
  65. }
  66.