home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / SMC21LIB.LZH / FREAD.C < prev    next >
Text File  |  2000-06-30  |  1KB  |  38 lines

  1.  
  2. #define NOCCARGC
  3. #include clib.def
  4. extern int _status[];
  5. /*
  6. ** Item-stream read from fd.
  7. ** Entry: buf = address of target buffer
  8. **        sz  = size of items in bytes
  9. **        n   = number of items to read
  10. **        fd  = file descriptor
  11. ** Returns a count of items actually read.
  12. ** Use feof() and ferror() to determine file status.
  13. */
  14. fread(buf, sz, n, fd) char *buf; int sz, n, fd; {
  15.   return(read(fd, buf, n*sz));
  16.   }
  17.  
  18. /*
  19. ** Binary-stream read from fd.
  20. ** Entry: fd  = file descriptor
  21. **        buf = address of target buffer
  22. **        n   = number of bytes to read
  23. ** Returns a count of items actually read
  24. ** Use feof() and ferror() to determine file status.
  25. */
  26. read(fd, buf, n) int fd, n; char *buf; {
  27.   char *cnt; /*fake unsigned*/
  28.   cnt = 0;
  29.   while(n--) {
  30.     *buf++ = _read(fd);
  31.     if(_status[fd] & (ERRBIT | EOFBIT)) break;
  32.     ++cnt;
  33.     }
  34.   return (cnt);
  35.   }
  36.  
  37.  
  38.