]> mj.ucw.cz Git - libucw.git/commitdiff
Bucket fastbuf's have to be seekable, since shep-reap seeks on them
authorMartin Mares <mj@ucw.cz>
Thu, 5 Aug 2004 22:28:58 +0000 (22:28 +0000)
committerMartin Mares <mj@ucw.cz>
Thu, 5 Aug 2004 22:28:58 +0000 (22:28 +0000)
(although the seek will be inside the buffer [and thence optimized out
by bseek()] under all reasonable circumstances [it was triggered by
a bug in buck2obj]).

lib/bucket.c

index f81f03e8d3f5444d0af9d3176edf932f0fe1b5a3..57fb83f430883376259d84bbfd98ee1a5db77804 100644 (file)
@@ -183,6 +183,16 @@ obuck_fb_refill(struct fastbuf *f)
   return datasize;
 }
 
+static void
+obuck_fb_seek(struct fastbuf *f, sh_off_t pos, int whence)
+{
+  ASSERT(whence == SEEK_SET || whence == SEEK_END);
+  if (whence == SEEK_END)
+    pos += FB_BUCKET(f)->bucket_size;
+  ASSERT(pos >= 0 && pos <= FB_BUCKET(f)->bucket_size);
+  f->pos = pos;
+}
+
 static void
 obuck_fb_spout(struct fastbuf *f)
 {
@@ -316,7 +326,7 @@ obuck_fetch(void)
   b->pos = 0;
   b->refill = obuck_fb_refill;
   b->spout = NULL;
-  b->seek = NULL;
+  b->seek = obuck_fb_seek;
   b->close = obuck_fb_close;
   b->config = NULL;
   b->can_overwrite_buffer = 2;