From: Martin Mares Date: Fri, 27 Sep 2002 21:45:40 +0000 (+0000) Subject: When writing, the data needn't start at the beginning of the buffer. X-Git-Tag: holmes-import~1335 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=2a5686e35c9d6be6cefe22d49cfff6d23ec2e842;p=libucw.git When writing, the data needn't start at the beginning of the buffer. (We need this for fb-mmap since the buffer is always page aligned.) --- diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 2631be06..d976730d 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -24,13 +24,10 @@ void bclose(struct fastbuf *f) void bflush(struct fastbuf *f) { - if (f->bptr != f->buffer) - { /* Have something to flush */ - if (f->bstop > f->buffer) /* Read data? */ - f->bptr = f->bstop = f->buffer; - else /* Write data... */ - f->spout(f); - } + if (f->bptr > f->bstop) + f->spout(f); + else if (f->bstop > f->buffer) + f->bptr = f->bstop = f->buffer; } inline void bsetpos(struct fastbuf *f, sh_off_t pos) diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 4f6c5e66..1f502ce5 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -36,11 +36,11 @@ * * When writing: * - * +----------------+---------------------------+ - * | written data | free space | - * +----------------+---------------------------+ - * ^ ^ ^ - * buffer=bstop bptr bufend + * +--------+--------------+--------------------+ + * | unused | written data | free space | + * +--------+--------------+--------------------+ + * ^ ^ ^ ^ + * buffer bstop bptr bufend * * Dirty tricks: *