ref: f8d5cc7230ee2cb7521d90599d525e205ad84fa6
dir: /sys/src/libbio/breadn.c/
#include <u.h> #include <libc.h> #include <bio.h> long Breadn(Biobufhdr *bp, void *data, long len) { char *e, *p; int n; p = data; e = p + len; if(e < p){ Berror(bp, "invalid read length"); return -1; } while(p < e){ if((n = Bread(bp, p, e - p)) <= 0){ if(n < 0 && p == data) return -1; break; } p += n; } return p - (char*)data; }