X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=lib%2Fbufio.c;h=1929d31620c4f19885c714b68592d01cfd159ab1;hb=8e01353ea837db6f80a154fafe9dea697ce03410;hp=4f2ad10bf5bac02b06c47193e2e410d5adc94050;hpb=4930589b97e949a602e82a77463051e0b83d119f;p=ashd.git diff --git a/lib/bufio.c b/lib/bufio.c index 4f2ad10..1929d31 100644 --- a/lib/bufio.c +++ b/lib/bufio.c @@ -228,6 +228,7 @@ ssize_t biowrite(struct bufio *bio, const void *data, size_t len) } if(len < bio->wbuf.s - bio->wbuf.d) { memcpy(bio->wbuf.b + bio->wbuf.d, data, len); + bio->wbuf.d += len; wb += len; len = 0; } else { @@ -247,7 +248,7 @@ ssize_t biowrite(struct bufio *bio, const void *data, size_t len) data += ret; len -= ret; wb += ret; } } - return(0); + return(wb); } ssize_t biowritesome(struct bufio *bio, const void *data, size_t len) @@ -258,14 +259,22 @@ ssize_t biowritesome(struct bufio *bio, const void *data, size_t len) if(bio->wh == bio->wbuf.d) bio->wh = bio->wbuf.d = 0; if(bio->wbuf.d == bio->wbuf.s) { - if(bio->wh > 0) + if(bio->wh > 0) { memmove(bio->wbuf.b, bio->wbuf.b + bio->wh, bio->wbuf.d -= bio->wh); + bio->wh = 0; + } } ret = min(len, bio->wbuf.s - bio->wbuf.d); memcpy(bio->wbuf.b + bio->wbuf.d, data, ret); bio->wbuf.d += ret; - if((bioflushsome(bio) < 0) && (ret == 0)) - return(-1); + if(bioflushsome(bio) < 0) { + if(ret == 0) + return(-1); + if(ret < bio->wbuf.d - bio->wh) { /* Should never be false */ + bio->wbuf.d -= ret; + return(-1); + } + } return(ret); }