X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Ffb-buffer.c;h=1888cd516b0d9bdced19b85cfe60d2c5f07d27f9;hb=57c188c449ae0ac47e8826f947c76eb1f4d26eaf;hp=3c377e06aa6d8657d7bcf277ee531bb7cbd66959;hpb=031256ad2e123eec58521f8e3eb9496c197641d2;p=libucw.git diff --git a/ucw/fb-buffer.c b/ucw/fb-buffer.c index 3c377e06..1888cd51 100644 --- a/ucw/fb-buffer.c +++ b/ucw/fb-buffer.c @@ -20,10 +20,10 @@ fbbuf_refill(struct fastbuf *f UNUSED) } static int -fbbuf_seek(struct fastbuf *f, sh_off_t pos, int whence) +fbbuf_seek(struct fastbuf *f, ucw_off_t pos, int whence) { /* Somebody might want to seek to the end of buffer, try to be nice to him. */ - sh_off_t len = f->bufend - f->buffer; + ucw_off_t len = f->bufend - f->buffer; if (whence == SEEK_END) pos += len; ASSERT(pos >= 0 && pos <= len); @@ -68,3 +68,51 @@ fbbuf_init_write(struct fastbuf *f, byte *buf, uns size) f->config = NULL; f->can_overwrite_buffer = 0; } + +#ifdef TEST + +int main(int argc, char *argv[]) +{ + if (argc < 2) + { + fprintf(stderr, "You must specify a test (r, w, o)\n"); + return 1; + } + switch (*argv[1]) + { + case 'r': + { + struct fastbuf fb; + char *data = "Two\nlines\n"; + fbbuf_init_read(&fb, data, strlen(data), 0); + char buffer[10]; + while (bgets(&fb, buffer, 10)) + puts(buffer); + bclose(&fb); + break; + } + case 'w': + { + struct fastbuf fb; + char buff[20]; + fbbuf_init_write(&fb, buff, 20); + bputs(&fb, "Hello world\n"); + bputc(&fb, 0); + fputs(buff, stdout); + break; + } + case 'o': + { + struct fastbuf fb; + char buff[4]; + fbbuf_init_write(&fb, buff, 4); + bputs(&fb, "Hello"); + bputc(&fb, 0); + fputs(buff, stdout); + break; + } + } + return 0; +} + +#endif