]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fastbuf.h
Defined a GET_TAGGED_CHAR macro to read our internal representation
[libucw.git] / lib / fastbuf.h
index e215b3ca6c455f54d10aba593e57fa625e9bb76f..d831ed36153a877f27d0cf5f9cb85d90ac615604 100644 (file)
@@ -4,6 +4,9 @@
  *     (c) 1997--2000 Martin Mares <mj@ucw.cz>
  */
 
+#ifndef _SHERLOCK_FASTBUF_H
+#define _SHERLOCK_FASTBUF_H
+
 #ifndef EOF
 #include <stdio.h>
 #endif
@@ -40,6 +43,7 @@ struct fastbuf {
   sh_off_t pos;                                /* Position of buffer start in the file */
   sh_off_t fdpos;                      /* Current position in the non-buffered file */
   int fd;                              /* File descriptor, -1 if not a real file */
+  int is_temp_file;                    /* Is a temporary file, delete on close */
   void *lldata;                                /* Data private to access functions below */
   void *llpos;                         /* ... continued ... */
   int (*refill)(struct fastbuf *);     /* Get a buffer with new data */
@@ -264,7 +268,7 @@ static inline void bput5(struct fastbuf *f, u64 l)
     bput5_slow(f, l);
 }
 
-uns bread_slow(struct fastbuf *f, void *b, uns l);
+uns bread_slow(struct fastbuf *f, void *b, uns l, uns check);
 static inline uns bread(struct fastbuf *f, void *b, uns l)
 {
   if (f->bptr + l <= f->bstop)
@@ -274,7 +278,19 @@ static inline uns bread(struct fastbuf *f, void *b, uns l)
       return l;
     }
   else
-    return bread_slow(f, b, l);
+    return bread_slow(f, b, l, 0);
+}
+
+static inline uns breadb(struct fastbuf *f, void *b, uns l)
+{
+  if (f->bptr + l <= f->bstop)
+    {
+      memcpy(b, f->bptr, l);
+      f->bptr += l;
+      return l;
+    }
+  else
+    return bread_slow(f, b, l, 1);
 }
 
 void bwrite_slow(struct fastbuf *f, void *b, uns l);
@@ -290,6 +306,7 @@ static inline void bwrite(struct fastbuf *f, void *b, uns l)
 }
 
 byte *bgets(struct fastbuf *f, byte *b, uns l);        /* Non-std */
+byte *bgets0(struct fastbuf *f, byte *b, uns l);
 
 static inline void
 bputs(struct fastbuf *f, byte *b)
@@ -297,6 +314,12 @@ bputs(struct fastbuf *f, byte *b)
   bwrite(f, b, strlen(b));
 }
 
+static inline void
+bputs0(struct fastbuf *f, byte *b)
+{
+  bwrite(f, b, strlen(b)+1);
+}
+
 static inline void
 bputsn(struct fastbuf *f, byte *b)
 {
@@ -304,6 +327,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
@@ -317,3 +346,5 @@ bputsn(struct fastbuf *f, byte *b)
 #define bgetp(f) bgetl(f)
 #define bputp(f,l) bputl(f,l)
 #endif
+
+#endif