]> mj.ucw.cz Git - libucw.git/commitdiff
Added "direct buffer I/O" interface for those who want to avoid an extra
authorMartin Mares <mj@ucw.cz>
Sun, 21 Jan 2001 14:14:04 +0000 (14:14 +0000)
committerMartin Mares <mj@ucw.cz>
Sun, 21 Jan 2001 14:14:04 +0000 (14:14 +0000)
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.

lib/fastbuf.c
lib/fastbuf.h

index 1895e9bd5d892893135f348dd1312a8ca377279c..5b394cf1c867c2f755b07db788a562ad3e3fb84c 100644 (file)
@@ -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;
+}
index 77345c2aaa438370def244669fbb7dab2821b589..f1f0239ae8dac3177855a5919502d287e823353f 100644 (file)
@@ -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