From: Jan 'Moskyt' Matejka Date: Mon, 9 Jul 2012 13:42:30 +0000 (+0200) Subject: Fastbuf: fbmulti allows reading of one subbuf more times X-Git-Tag: v5.99~129 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=9f337d4b2be7124ec44c4701ba3816a2831ce9c5;p=libucw.git Fastbuf: fbmulti allows reading of one subbuf more times --- diff --git a/ucw/fb-multi.c b/ucw/fb-multi.c index 20d8590e..c9eac151 100644 --- a/ucw/fb-multi.c +++ b/ucw/fb-multi.c @@ -46,8 +46,11 @@ fbmulti_subbuf_next(struct fastbuf *f) if (next == NULL) return 0; - if (f->seek) + if (f->seek) { + bseek(FB_MULTI(f)->cur->fb, 0, SEEK_SET); next->begin = FB_MULTI(f)->cur->end; + } + FB_MULTI(f)->cur = next; return 1; } @@ -219,6 +222,24 @@ int main(int argc, char ** argv) putchar(bgetc(f)); } + bclose(f); + break; + } + case 'i': + { + char *data = "Insae"; + struct fastbuf fb[4]; + fbbuf_init_read(&fb[0], data, 1, 0); + fbbuf_init_read(&fb[1], data + 1, 1, 0); + fbbuf_init_read(&fb[2], data + 2, 2, 0); + fbbuf_init_read(&fb[3], data + 4, 1, 0); + + struct fastbuf* f = fbmulti_create(8, &fb[0], &fb[1], &fb[2], &fb[1], &fb[3], NULL); + + char buffer[9]; + while(bgets(f, buffer, 9)) + puts(buffer); + bclose(f); break; } diff --git a/ucw/fb-multi.t b/ucw/fb-multi.t index de8190fd..0b8a11fc 100644 --- a/ucw/fb-multi.t +++ b/ucw/fb-multi.t @@ -11,3 +11,7 @@ Out: One Name: Read Mingle Run: ../obj/ucw/fb-multi-t m Out: Mingle + +Name: Read Insane +Run: ../obj/ucw/fb-multi-t i +Out: Insane