]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.h
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / fastbuf.h
index 12047038486e8f580372b6c8736503598ea712c4..af6787aeaf5cc29a2f3e28856c0aa0cf18d85fab 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *     Sherlock Library -- Fast Buffered I/O
+ *     UCW Library -- Fast Buffered I/O
  *
  *     (c) 1997--2004 Martin Mares <mj@ucw.cz>
  *     (c) 2004 Robert Spalek <robert@ucw.cz>
@@ -8,8 +8,8 @@
  *     of the GNU Lesser General Public License.
  */
 
-#ifndef _SHERLOCK_FASTBUF_H
-#define _SHERLOCK_FASTBUF_H
+#ifndef _UCW_FASTBUF_H
+#define _UCW_FASTBUF_H
 
 #ifndef EOF
 #include <stdio.h>
@@ -81,6 +81,7 @@ struct fastbuf {
 /* FastIO on standard files (specify buffer size 0 to enable mmaping) */
 
 struct fastbuf *bopen(byte *name, uns mode, uns buflen);
+struct fastbuf *bopen_try(byte *name, uns mode, uns buflen);
 struct fastbuf *bopen_tmp(uns buflen);
 struct fastbuf *bfdopen(int fd, uns buflen);
 struct fastbuf *bfdopen_shared(int fd, uns buflen);
@@ -109,6 +110,12 @@ fbbuf_count_written(struct fastbuf *f)
   return f->bptr - f->bstop;
 }
 
+/* FastIO on recyclable growing buffers */
+
+struct fastbuf *fbgrow_create(unsigned basic_size);
+void fbgrow_reset(struct fastbuf *b);                  /* Reset stream and prepare for writing */
+void fbgrow_rewind(struct fastbuf *b);                 /* Prepare for reading */
+
 /* Configuring stream parameters */
 
 int bconfig(struct fastbuf *f, uns type, int data);
@@ -373,7 +380,10 @@ static inline uns
 bdirect_read_prepare(struct fastbuf *f, byte **buf)
 {
   if (f->bptr == f->bstop && !f->refill(f))
-    return 0;
+    {
+      *buf = NULL;  // This is not needed, but it helps to get rid of spurious warnings
+      return 0;
+    }
   *buf = f->bptr;
   return bavailr(f);
 }
@@ -408,7 +418,7 @@ bdirect_write_commit(struct fastbuf *f, byte *pos)
 
 /* Formatted output */
 
-int bprintf(struct fastbuf *b, byte *msg, ...);
-int vbprintf(struct fastbuf *b, byte *msg, va_list args);
+int bprintf(struct fastbuf *b, char *msg, ...) FORMAT_CHECK(printf,2,3);
+int vbprintf(struct fastbuf *b, char *msg, va_list args);
 
 #endif