home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / procssng / ccs / ccs-11tl.lha / lbl / lib / pread.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-21  |  760 b   |  45 lines

  1. /*
  2. %    pread.c - pipe in read subroutine which waits for its input count
  3. %        or EOF
  4. %
  5. @    For use with pipes, which return on read with that which is available
  6. @        rather than that which is requested.
  7. @
  8. @    10/1/90    -- fixed for multiple machine to use by use MType
  9. */
  10.  
  11. #ifdef    _DEBUG_
  12. extern    int    debug;
  13. #endif
  14.  
  15. #include "header.def"
  16. #include "images.def"
  17.  
  18. #ifdef    IBMPC
  19. #define    MASK    0x0000FFFF
  20. #else
  21. #define    MASK    0xFFFFFFFF
  22. #endif
  23.  
  24. PType    pread(fd,buf,count)
  25. int    fd;
  26. PType    count;
  27. char    *buf;
  28. {
  29. static PType    memc;
  30. PType    r, cnt = count;
  31.  
  32. while (cnt > 0) {
  33.     r = MASK & read(fd,buf,(unsigned)cnt);
  34. #ifdef    _DEBUG_
  35.     if (debug)
  36.         if (r!=memc)    msg("pread in %d\n", memc=r);
  37.         else    mesg(" =*= ");
  38. #endif
  39.     if (r <= 0) break;
  40.     buf += r;
  41.     cnt -= r;
  42.   }
  43. return    (PType)(count - cnt);
  44. }
  45.