* of the GNU Lesser General Public License.
*/
-#include "ucw/lib.h"
-#include "ucw/fastbuf.h"
+#include <ucw/lib.h>
+#include <ucw/fastbuf.h>
#include <stdio.h>
#include <stdlib.h>
static int
-fbbuf_refill(struct fastbuf *f UNUSED)
+fbbuf_refill(struct fastbuf *f)
{
- return 0;
+ f->bstop = f->bufend;
+ f->pos = f->bstop - f->buffer;
+ return f->bptr < f->bstop;
}
static int
ucw_off_t len = f->bufend - f->buffer;
if (whence == SEEK_END)
pos += len;
- ASSERT(pos >= 0 && pos <= len);
- f->bptr = f->buffer + pos;
- f->bstop = f->bufend;
- f->pos = len;
+ if (pos < 0 || pos > len)
+ bthrow(f, "seek", "Seek out of range");
+ f->bstop = f->bptr = f->buffer + pos;
+ f->pos = pos;
return 1;
}
void
-fbbuf_init_read(struct fastbuf *f, byte *buf, uns size, uns can_overwrite)
+fbbuf_init_read(struct fastbuf *f, byte *buf, uint size, uint can_overwrite)
{
*f = (struct fastbuf) {
.buffer = buf,
static void
fbbuf_spout(struct fastbuf *f)
{
- bthrow(f, "fb.write", "fbbuf: buffer overflow on write");
+ bthrow(f, "write", "fbbuf: buffer overflow on write");
}
void
-fbbuf_init_write(struct fastbuf *f, byte *buf, uns size)
+fbbuf_init_write(struct fastbuf *f, byte *buf, uint size)
{
*f = (struct fastbuf) {
.buffer = buf,
.bptr = buf,
.bufend = buf + size,
.name = "fbbuf-write",
- .pos = size,
.spout = fbbuf_spout,
};
}