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.
 
 
 
 

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