home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / OPENA.CAS < prev    next >
Encoding:
Text File  |  1992-06-10  |  1.9 KB  |  67 lines

  1. /*-----------------------------------------------------------------------*
  2.  * filename - opena.cas
  3.  *
  4.  * function(s)
  5.  *        _open - opens a file for reading or writing
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <io.h>
  20. #include <fcntl.h>
  21. #include <_io.h>
  22. #include <RtlData.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 _FARFUNC _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.                 _RTLInstanceData(_openfd)[fd] =
  61.                 (oflag & ~(_O_RUNFLAGS | O_TEXT)) | O_BINARY;
  62.                 return(fd);
  63.  
  64. _openFailed:
  65.                 return __IOerror (_AX);
  66. }
  67.