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 / FWRITE.C < prev    next >
Text File  |  2000-06-30  |  1KB  |  42 lines

  1.  
  2. #define NOCCARGC
  3. #include clib.def
  4. extern int _status[];
  5. /*
  6. ** Item-stream write to 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. ** or zero if an error occured.
  13. ** Use ferror() to determine file status.
  14. */
  15. fwrite(buf, sz, n, fd) char *buf; int sz, n, fd; {
  16.   int cnt;
  17.   if((cnt = write(fd, buf, n*sz)) == -1) return (0);
  18.   return (cnt);
  19.   }
  20.  
  21. /*
  22. ** Binary-stream write to fd.
  23. ** Entry: buf = address of target buffer
  24. **        n   = number of items to read
  25. **        fd  = file descriptor
  26. ** Returns a count of items actually read
  27. ** or -1 if an error occured.
  28. ** Use ferror() to determine file status.
  29. */
  30. write(fd, buf, n) int fd, n; char *buf; {
  31.   char *cnt;  /*fake unsigned*/
  32.   cnt = 0;
  33.   while(n--)  {
  34.     _write(*buf++, fd);
  35.     if(_status[fd] & ERRBIT) return (-1);
  36.     ++cnt;
  37.     }
  38.   return (cnt);
  39.   }
  40.  
  41.  
  42.