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

  1. /*-----------------------------------------------------------------------*
  2.  * filename - reada.cas
  3.  *
  4.  * function(s)
  5.  *        _read - reads from file
  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 <_io.h>
  21. #include <fcntl.h>
  22. #include <RtlData.h>
  23.  
  24. /*-----------------------------------------------------------------------*
  25.  
  26. Name            _read - reads from file
  27.  
  28. Usage           int _read(int handle, void *buf, unsigned nbyte);
  29.  
  30. Prototype in    io.h
  31.  
  32. Description     _read is a direct call to the MS-DOS read system call.
  33.                 see read in READ.CAS
  34.  
  35. Return value    Upon successful completion, a positive integer is
  36.                 returned indicating the number of bytes placed in the buffer;
  37.                 if the file was opened in text mode, read does not count
  38.                 carriage returns or <Ctrl-Z> characters in the number of
  39.                 bytes read.
  40.  
  41.                 On end-of-file, both functions return zero. On error, both
  42.                 functions return -1 and errno is set to one of the following:
  43.  
  44.                         EACCES  Permission denied
  45.                         EBADF   Bad file number
  46.  
  47. *------------------------------------------------------------------------*/
  48. #ifdef _Windows
  49. extern int (*__ReadBufFPtr)(char *Buffer, unsigned Count);
  50. #endif
  51.  
  52. int _CType _read( int fd, void *buf, unsigned len )
  53. {
  54.     if (_RTLInstanceData(_openfd)[fd] & O_WRONLY)
  55.         return __IOerror(e_accessDenied);
  56.  
  57. #ifdef _Windows
  58.     if (__ReadBufFPtr)
  59.         if (isatty(fd))
  60.             return __ReadBufFPtr((char *)buf, len);
  61. #endif
  62.         pushDS_
  63.     asm mov ah,3fh
  64.     asm mov bx,fd
  65.     asm mov cx,len
  66.     asm LDS_    dx, buf
  67.     asm int 21h
  68.         popDS_
  69.     asm jc  _readFailed
  70.     return(_AX);
  71.  
  72. _readFailed:
  73.     return __IOerror (_AX);
  74. }
  75.