From: Martin Mares Date: Sun, 21 Jan 2001 14:14:04 +0000 (+0000) Subject: Added "direct buffer I/O" interface for those who want to avoid an extra X-Git-Tag: holmes-import~1579 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=417d2511bb77568e041fef8ea14406b265124066;p=libucw.git Added "direct buffer I/O" interface for those who want to avoid an extra copy of data during read/write at expense of having to be prepared for any data size the buffering layer tells them to read/write. --- diff --git a/lib/fastbuf.c b/lib/fastbuf.c index 1895e9bd..5b394cf1 100644 --- a/lib/fastbuf.c +++ b/lib/fastbuf.c @@ -253,3 +253,31 @@ bgets(struct fastbuf *f, byte *b, uns l) } die("%s: Line too long", f->name); } + +int +bdirect_read(struct fastbuf *f, byte **buf) +{ + int len; + + if (f->bptr == f->bstop && !f->refill(f)) + return EOF; + *buf = f->bptr; + len = f->bstop - f->bptr; + f->bptr += len; + return len; +} + +int +bdirect_write_prepare(struct fastbuf *f, byte **buf) +{ + if (f->bptr == f->bufend) + f->spout(f); + *buf = f->bptr; + return f->bufend - f->bptr; +} + +void +bdirect_write_commit(struct fastbuf *f, byte *pos) +{ + f->bptr = pos; +} diff --git a/lib/fastbuf.h b/lib/fastbuf.h index 77345c2a..f1f0239a 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -307,6 +307,12 @@ bputsn(struct fastbuf *f, byte *b) bputc(f, '\n'); } +/* Direct I/O on buffers */ + +int bdirect_read(struct fastbuf *f, byte **buf); +int bdirect_write_prepare(struct fastbuf *f, byte **buf); +void bdirect_write_commit(struct fastbuf *f, byte *pos); + /* Depending on compile-time configuration, we select the right function for reading/writing of file offsets */ #ifdef SHERLOCK_CONFIG_LARGE_DB