]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.h
sped up approximately 6 times:
[libucw.git] / lib / fastbuf.h
index 5ee23d48c88c556e0e25bb7ab1c20d9a1880b48d..2ed05341dbcaa42b7268b09abd83de112024aba6 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Sherlock Library -- Fast Buffered I/O
  *
- *     (c) 1997--2002 Martin Mares <mj@ucw.cz>
+ *     (c) 1997--2004 Martin Mares <mj@ucw.cz>
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
@@ -65,7 +65,7 @@ struct fastbuf {
   int (*config)(struct fastbuf *, uns, int);   /* Configure the stream */
 };
 
-/* FastIO on standard files */
+/* FastIO on standard files (specify buffer size 0 to enable mmaping) */
 
 struct fastbuf *bopen(byte *name, uns mode, uns buffer);
 struct fastbuf *bopen_tmp(uns buffer);
@@ -81,6 +81,20 @@ struct fastbuf *fbmem_clone_read(struct fastbuf *);  /* Create reading fastbuf */
 
 struct fastbuf *bopen_mm(byte *name, uns mode);
 
+/* FastI on file descriptors with limit */
+
+struct fastbuf *bopen_limited_fd(int fd, uns bufsize, uns limit);
+
+/* FastIO on static buffers */
+
+void fbbuf_init_read(struct fastbuf *f, byte *buffer, uns size);
+void fbbuf_init_write(struct fastbuf *f, byte *buffer, uns size);
+static inline uns
+fbbuf_count_written(struct fastbuf *f)
+{
+  return f->bptr - f->bstop;
+}
+
 /* Configuring stream parameters */
 
 int bconfig(struct fastbuf *f, uns type, int data);
@@ -93,6 +107,7 @@ void bclose(struct fastbuf *f);
 void bflush(struct fastbuf *f);
 void bseek(struct fastbuf *f, sh_off_t pos, int whence);
 void bsetpos(struct fastbuf *f, sh_off_t pos);
+void brewind(struct fastbuf *f);
 
 static inline sh_off_t btell(struct fastbuf *f)
 {
@@ -267,6 +282,7 @@ static inline void bwrite(struct fastbuf *f, void *b, uns l)
 }
 
 byte *bgets(struct fastbuf *f, byte *b, uns l);        /* Non-std */
+int bgets_nodie(struct fastbuf *f, byte *b, uns l);
 byte *bgets0(struct fastbuf *f, byte *b, uns l);
 
 static inline void
@@ -315,11 +331,11 @@ bbcopy(struct fastbuf *f, struct fastbuf *t, uns l)
 
 /* Direct I/O on buffers */
 
-static inline int
+static inline uns
 bdirect_read_prepare(struct fastbuf *f, byte **buf)
 {
   if (f->bptr == f->bstop && !f->refill(f))
-    return EOF;
+    return 0;
   *buf = f->bptr;
   return f->bstop - f->bptr;
 }
@@ -330,7 +346,7 @@ bdirect_read_commit(struct fastbuf *f, byte *pos)
   f->bptr = pos;
 }
 
-static inline int
+static inline uns
 bdirect_write_prepare(struct fastbuf *f, byte **buf)
 {
   if (f->bptr == f->bufend)
@@ -345,4 +361,9 @@ bdirect_write_commit(struct fastbuf *f, byte *pos)
   f->bptr = pos;
 }
 
+/* Formatted output */
+
+int bprintf(struct fastbuf *b, byte *msg, ...);
+int vbprintf(struct fastbuf *b, byte *msg, va_list args);
+
 #endif