/*
- * Sherlock Library -- Fast Buffered I/O on Memory Streams
+ * UCW Library -- Fast Buffered I/O on Memory Streams
*
* (c) 1997--2002 Martin Mares <mj@ucw.cz>
*
#include "lib/lib.h"
#include "lib/fastbuf.h"
-#include <stdlib.h>
-
struct memstream {
unsigned blocksize;
unsigned uc;
/* Yes, this is linear. But considering the average number of buckets, it doesn't matter. */
for (b=m->first; b; b=b->next)
{
- if (pos <= b->pos + b->size) /* <=, because we need to be able to seek just after file end */
+ if (pos <= b->pos + (sh_off_t)b->size) /* <=, because we need to be able to seek just after file end */
{
f->buffer = b->data;
f->bptr = b->data + (pos - b->pos);
return;
}
}
+ if (!m->first && !pos)
+ {
+ /* Seeking to offset 0 in an empty file needs an exception */
+ f->buffer = f->bptr = f->bufend = NULL;
+ f->pos = 0;
+ FB_MEM(f)->block = NULL;
+ return;
+ }
die("fbmem_seek to invalid offset");
}
f->refill = fbmem_refill;
f->seek = fbmem_seek;
f->close = fbmem_close;
+ f->can_overwrite_buffer = 1;
return f;
}