home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / dos / io / _read.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-25  |  1.1 KB  |  53 lines

  1. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  2. #include <libc/stubs.h>
  3. #include <unistd.h>
  4. #include <string.h>
  5. #include <errno.h>
  6. #include <go32.h>
  7. #include <dpmi.h>
  8. #include <io.h>
  9. #include <sys/fsext.h>
  10.  
  11. #include <libc/dosio.h>
  12.  
  13. int
  14. _read(int handle, void* buffer, size_t count)
  15. {
  16.   size_t j, k;
  17.   int ngot;
  18.   unsigned long tbsize;
  19.   __dpmi_regs r;
  20.  
  21.   __FSEXT_Function *func = __FSEXT_get_function(handle);
  22.   if (func)
  23.   {
  24.     int rv;
  25.     if (func(__FSEXT_read, &rv, &handle))
  26.       return rv;
  27.   }
  28.  
  29.   tbsize = _go32_info_block.size_of_transfer_buffer;
  30.   ngot = 0;
  31.   do {
  32.     j = (count <= tbsize) ? count : tbsize;
  33.     r.x.ax = 0x3f00;
  34.     r.x.bx = handle;
  35.     r.x.cx = j;
  36.     r.x.dx = __tb & 15;
  37.     r.x.ds = __tb / 16;
  38.     __dpmi_int(0x21, &r);
  39.     if(r.x.flags & 1)
  40.     {
  41.       errno = __doserr_to_errno(r.x.ax);
  42.       return -1;
  43.     }
  44.     count -= j;
  45.     k = r.x.ax;
  46.     ngot += k;
  47.     if (k)
  48.       dosmemget(__tb, k, buffer);
  49.     buffer = (void *)((int)buffer + k);
  50.   } while(count && j == k);    /* if not == on DOS then no more */
  51.   return ngot;
  52. }
  53.