From da335e3d0f8e81cd6747084f49a456ed59e6d65c Mon Sep 17 00:00:00 2001 From: Jan 'Moskyt' Matejka Date: Mon, 9 Jul 2012 16:49:21 +0200 Subject: [PATCH] Fastbuf: fbmulti nested test and apropriate fixes --- ucw/fb-multi.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- ucw/fb-multi.t | 6 ++++++ 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ucw/fb-multi.c b/ucw/fb-multi.c index c9eac151..e5ab5bdc 100644 --- a/ucw/fb-multi.c +++ b/ucw/fb-multi.c @@ -47,7 +47,7 @@ fbmulti_subbuf_next(struct fastbuf *f) return 0; if (f->seek) { - bseek(FB_MULTI(f)->cur->fb, 0, SEEK_SET); + bseek(next->fb, 0, SEEK_SET); next->begin = FB_MULTI(f)->cur->end; } @@ -109,8 +109,12 @@ fbmulti_seek(struct fastbuf *f, ucw_off_t pos, int whence) if (pos < FB_MULTI(f)->cur->end) break; - if (!fbmulti_subbuf_next(f)) - bthrow(f, "seek", "Seek out of range"); + if (!fbmulti_subbuf_next(f)) { + if (pos == FB_MULTI(f)->cur->end) + break; + else + bthrow(f, "seek", "Seek out of range"); + } } while (1); @@ -122,7 +126,7 @@ fbmulti_seek(struct fastbuf *f, ucw_off_t pos, int whence) case SEEK_END: fbmulti_get_len(f); - return fbmulti_seek(f, FB_MULTI(f)->len+pos, SEEK_CUR); + return fbmulti_seek(f, FB_MULTI(f)->len+pos, SEEK_SET); break; default: @@ -240,6 +244,47 @@ int main(int argc, char ** argv) while(bgets(f, buffer, 9)) puts(buffer); + bclose(f); + break; + } + case 'n': + { + char *data[] = { "Nested", "Data", "As", "In", "Real", "Usage", }; + struct fastbuf fb[ARRAY_SIZE(data)]; + for (uns i=0;i