1 #include <u.h> 2 #include <libc.h> 3 4 static 5 long 6 iowritev(int fd, IOchunk *io, int nio, vlong offset) 7 { 8 int i; 9 long tot; 10 char *buf, *p; 11 12 tot = 0; 13 for(i=0; i<nio; i++) 14 tot += io[i].len; 15 buf = malloc(tot); 16 if(buf == nil) 17 return -1; 18 19 p = buf; 20 for(i=0; i<nio; i++){ 21 memmove(p, io->addr, io->len); 22 p += io->len; 23 io++; 24 } 25 26 tot = pwrite(fd, buf, tot, offset); 27 28 free(buf); 29 return tot; 30 } 31 32 long 33 writev(int fd, IOchunk *io, int nio) 34 { 35 return iowritev(fd, io, nio, -1LL); 36 } 37 38 long 39 pwritev(int fd, IOchunk *io, int nio, vlong off) 40 { 41 return iowritev(fd, io, nio, off); 42 } 43