]> mj.ucw.cz Git - libucw.git/blobdiff - lib/fb-limfd.c
lib: added {big,page}_alloc_zero routines
[libucw.git] / lib / fb-limfd.c
index 7e07e328f94a0d6de2bac582d9641fb412d86511..50bc5215d568d6d5253c091abe96fa4bece21b5a 100644 (file)
@@ -1,8 +1,7 @@
 /*
 /*
- *     Sherlock Library -- Fast Buffered Input on Limited File Descriptors
+ *     UCW Library -- Fast Buffered Input on Limited File Descriptors
  *
  *
- *     (c) 2003 Martin Mares <mj@ucw.cz>
- *     (c) 2004 Robert Spalek <robert@ucw.cz>
+ *     (c) 2003--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.
  *
  *     This software may be freely distributed and used according to the terms
  *     of the GNU Lesser General Public License.
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 
 #include "lib/lib.h"
 #include "lib/fastbuf.h"
 
-#include <stdlib.h>
 #include <unistd.h>
 
 struct fb_limfd {
   struct fastbuf fb;
   int fd;                              /* File descriptor */
   int limit;
 #include <unistd.h>
 
 struct fb_limfd {
   struct fastbuf fb;
   int fd;                              /* File descriptor */
   int limit;
-  int can_overwrite;
 };
 #define FB_LIMFD(f) ((struct fb_limfd *)(f)->is_fastbuf)
 };
 #define FB_LIMFD(f) ((struct fb_limfd *)(f)->is_fastbuf)
+#define FB_BUFFER(f) (byte *)(FB_LIMFD(f) + 1)
 
 static int
 bfl_refill(struct fastbuf *f)
 {
 
 static int
 bfl_refill(struct fastbuf *f)
 {
+  f->bptr = f->buffer = FB_BUFFER(f);
   int max = MIN(FB_LIMFD(f)->limit - f->pos, f->bufend - f->buffer);
   int l = read(FB_LIMFD(f)->fd, f->buffer, max);
   if (l < 0)
     die("Error reading %s: %m", f->name);
   int max = MIN(FB_LIMFD(f)->limit - f->pos, f->bufend - f->buffer);
   int l = read(FB_LIMFD(f)->fd, f->buffer, max);
   if (l < 0)
     die("Error reading %s: %m", f->name);
-  f->bptr = f->buffer;
   f->bstop = f->buffer + l;
   f->pos += l;
   return l;
   f->bstop = f->buffer + l;
   f->pos += l;
   return l;
@@ -41,21 +39,6 @@ bfl_close(struct fastbuf *f)
   xfree(f);
 }
 
   xfree(f);
 }
 
-static int
-bfl_config(struct fastbuf *f, uns item, int value)
-{
-  switch (item)
-    {
-    case BCONFIG_CAN_OVERWRITE: ;
-      int old_value = FB_LIMFD(f)->can_overwrite;
-      if (value >= 0 && value <= 2)
-       FB_LIMFD(f)->can_overwrite = value;
-      return old_value;
-    default:
-      return -1;
-    }
-}
-
 struct fastbuf *
 bopen_limited_fd(int fd, uns buflen, uns limit)
 {
 struct fastbuf *
 bopen_limited_fd(int fd, uns buflen, uns limit)
 {
@@ -71,8 +54,7 @@ bopen_limited_fd(int fd, uns buflen, uns limit)
   F->limit = limit;
   f->refill = bfl_refill;
   f->close = bfl_close;
   F->limit = limit;
   f->refill = bfl_refill;
   f->close = bfl_close;
-  f->config = bfl_config;
-  F->can_overwrite = 2;
+  f->can_overwrite_buffer = 2;
   return f;
 }
 
   return f;
 }