Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
926 B

  1. #include <iob_internal.h>
  2. int64 iob_write(int64 s,io_batch* b,io_write_callback cb) {
  3. iob_entry* e,* last;
  4. int64 total,sent;
  5. long i;
  6. int thatsit;
  7. if (b->bytesleft==0) return 0;
  8. last=(iob_entry*)(((char*)array_start(&b->b))+array_bytes(&b->b));
  9. total=0;
  10. if (!(e=array_get(&b->b,sizeof(iob_entry),b->next)))
  11. return -3; /* can't happen error */
  12. thatsit=0;
  13. for (i=0; e+i<last; ++i) {
  14. if (!e[i].n) continue;
  15. if (e[i].type==FROMFILE || e[i].type==FROMFILE_CLOSE)
  16. sent=io_mmapwritefile(s,e[i].fd,e[i].offset,e[i].n,cb);
  17. else
  18. sent=cb(s,e[i].buf+e[i].offset,e[i].n);
  19. if (sent>0 && sent>e[i].n) sent=e[i].n; /* can't happen */
  20. thatsit=(sent != e[i].n);
  21. if (sent<=0)
  22. return total?total:sent;
  23. e[i].offset+=sent;
  24. e[i].n-=sent;
  25. total+=sent;
  26. b->bytesleft-=sent;
  27. if (thatsit) break;
  28. }
  29. if (total == b->bytesleft)
  30. iob_reset(b);
  31. return total;
  32. }