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

  1. /*-----------------------------------------------------------------------*
  2.  * filename - _dos_open.cas
  3.  *
  4.  * function(s)
  5.  *        _dos_open - opens a file for reading or writing (MSC)
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1991, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #pragma inline
  18. #include <asmrules.h>
  19. #include <fcntl.h>
  20. #include <_io.h>
  21.  
  22. /*-----------------------------------------------------------------------*
  23.  
  24. Name            _dos_open - opens a file for reading or writing
  25.  
  26. Usage           #include <fcntl.h>
  27.                 unsigned _dos_open(const char *pathname, unsigned oflag,
  28.                                 int *handle);
  29.  
  30. Prototype in    dos.h
  31.  
  32. Description     _dos_open opens the file pathname with the access mode
  33.                 specified by oflag.  See _open for information on
  34.                 oflag.  If the open is successful, the file handle
  35.                 is stored at *handle.
  36.  
  37. Return value    success : 0
  38.                 else    : the DOS error code, and errno is set.
  39.  
  40. Note            Compatible with Microsoft C.  Not the same as _open().
  41.  
  42. *------------------------------------------------------------------------*/
  43.  
  44. unsigned _dos_open (const char *pathP, unsigned oflag, int *handle )
  45. {
  46. /* Convert Borland access mode flags to DOS access mode:
  47.  *      Borland         DOS
  48.  *      =======         ===
  49.  *      O_RDONLY        0
  50.  *      O_WRONLY        1
  51.  *      O_RDWR          2
  52.  */
  53. asm     mov     cl, oflag
  54. asm     mov     al, 1
  55. asm     test    cl, O_WRONLY
  56. asm     jnz     ready
  57. asm     mov     al, 2
  58. asm     test    cl, O_RDWR
  59. asm     jnz     ready
  60. asm     mov     al, 0   /* assume O_RDONLY is set, since others aren't */
  61.  
  62. /* Put DOS inheritance and sharing flags in high nibble of access mode,
  63.  * and open the file.
  64.  */
  65. ready:
  66. asm     and     cl, 0F0h
  67. asm     or      al, cl
  68. asm     mov     ah, 3Dh
  69.         pushDS_
  70. asm     LDS_    dx, pathP
  71. asm     int     21h             /* AX = open (DS:DX, AL) */
  72.         popDS_
  73. asm     jc      _openFailed
  74.  
  75. asm     LES_    bx,handle       /* *handle = fd */
  76. asm     mov     ES_ [bx],ax
  77.         return (0);
  78.  
  79. _openFailed:
  80.         return (__DOSerror(_AX));       /* set errno */
  81. }
  82.