X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=ucw%2Ffastbuf.c;h=22501f43ed87cba8ff3e1529da0ebe2b57038b8c;hb=1481eca416a467e9952dbc5e4852afe66eaf1256;hp=7bec4bfd4b08b8d9a20b53f249cd2fbb8d700f03;hpb=92c1eac70f981f73950853ecedf556d2a9addf8a;p=libucw.git diff --git a/ucw/fastbuf.c b/ucw/fastbuf.c index 7bec4bfd..22501f43 100644 --- a/ucw/fastbuf.c +++ b/ucw/fastbuf.c @@ -9,11 +9,11 @@ #undef LOCAL_DEBUG -#include "ucw/lib.h" -#include "ucw/fastbuf.h" -#include "ucw/respool.h" -#include "ucw/trans.h" -#include "ucw/stkstring.h" +#include +#include +#include +#include +#include #include #include @@ -32,15 +32,17 @@ void bclose(struct fastbuf *f) void NONRET bthrow(struct fastbuf *f, const char *id, const char *fmt, ...) { + DBG("FB: throwing %s", full_id); + char full_id[16]; + snprintf(full_id, sizeof(full_id), "ucw.fb.%s", id); ASSERT(!(f->flags & FB_DEAD)); /* Only one bthrow() is allowed before bclose() */ - DBG("FB: throwing %s", id); va_list args; va_start(args, fmt); if (!f->res) die("Fastbuf %s error: %s", f->name ? : "", stk_vprintf(fmt, args)); f->flags |= FB_DEAD; f->bptr = f->bstop = f->bufend; /* Reset the buffer to guard consecutive seek/read/write */ - trans_vthrow(id, f, fmt, args); + trans_vthrow(full_id, f, fmt, args); } int brefill(struct fastbuf *f, int allow_eof) @@ -48,7 +50,7 @@ int brefill(struct fastbuf *f, int allow_eof) DBG("FB: refill"); ASSERT(!(f->flags & FB_DEAD) && f->buffer <= f->bstop && f->bstop <= f->bptr && f->bptr <= f->bufend); if (!f->refill) - bthrow(f, "fb.read", "Stream not readable"); + bthrow(f, "read", "Stream not readable"); if (f->refill(f)) { ASSERT(f->buffer <= f->bptr && f->bptr < f->bstop && f->bstop <= f->bufend); @@ -58,7 +60,7 @@ int brefill(struct fastbuf *f, int allow_eof) { ASSERT(f->buffer <= f->bptr && f->bptr == f->bstop && f->bstop <= f->bufend); if (!allow_eof && (f->flags & FB_DIE_ON_EOF)) - bthrow(f, "fb.eof", "Unexpected EOF"); + bthrow(f, "eof", "Unexpected EOF"); return 0; } } @@ -68,7 +70,7 @@ static void do_spout(struct fastbuf *f) DBG("FB: spout"); ASSERT(!(f->flags & FB_DEAD) && f->buffer <= f->bstop && f->bstop <= f->bptr && f->bptr <= f->bufend); /* Check write mode possibly with unflushed data */ if (!f->spout) - bthrow(f, "fb.write", "Stream not writeable"); + bthrow(f, "write", "Stream not writeable"); f->spout(f); ASSERT(f->buffer <= f->bstop && f->bstop <= f->bptr && f->bptr <= f->bufend); } @@ -97,7 +99,7 @@ static void do_seek(struct fastbuf *f, ucw_off_t pos, int whence) bflush(f); DBG("FB: seeking to pos=%lld whence=%d %p %p %p %p", (long long)pos, whence, f->buffer, f->bstop, f->bptr, f->bufend); if (!f->seek || !f->seek(f, pos, whence)) - bthrow(f, "fb.seek", "Stream not seekable"); + bthrow(f, "seek", "Stream not seekable"); DBG("FB: seeked %p %p %p %p", f->buffer, f->bstop, f->bptr, f->bufend); ASSERT(f->buffer <= f->bstop && f->bstop <= f->bptr && f->bptr <= f->bufend); if (whence == SEEK_SET) @@ -106,7 +108,7 @@ static void do_seek(struct fastbuf *f, ucw_off_t pos, int whence) ASSERT(btell(f) >= 0); } -inline void bsetpos(struct fastbuf *f, ucw_off_t pos) +void bsetpos(struct fastbuf *f, ucw_off_t pos) { /* We can optimize seeks only when reading */ if (f->bptr < f->bstop && pos <= f->pos && pos >= f->pos - (f->bstop - f->buffer)) /* If bptr == bstop, then [buffer, bstop] may be undefined */ @@ -114,7 +116,7 @@ inline void bsetpos(struct fastbuf *f, ucw_off_t pos) else if (pos != btell(f)) { if (pos < 0) - bthrow(f, "fb.seek", "Seek out of range"); + bthrow(f, "seek", "Seek out of range"); do_seek(f, pos, SEEK_SET); } } @@ -131,7 +133,7 @@ void bseek(struct fastbuf *f, ucw_off_t pos, int whence) break; case SEEK_END: if (pos > 0) - bthrow(f, "fb.seek", "Seek out of range"); + bthrow(f, "seek", "Seek out of range"); do_seek(f, pos, SEEK_END); break; default: @@ -162,19 +164,19 @@ int beof_slow(struct fastbuf *f) return f->bptr >= f->bstop && !brefill(f, 1); } -void bputc_slow(struct fastbuf *f, uns c) +void bputc_slow(struct fastbuf *f, uint c) { if (f->bptr >= f->bufend) bspout(f); *f->bptr++ = c; } -uns bread_slow(struct fastbuf *f, void *b, uns l, uns check) +uint bread_slow(struct fastbuf *f, void *b, uint l, uint check) { - uns total = 0; + uint total = 0; while (l) { - uns k = f->bstop - f->bptr; + uint k = f->bstop - f->bptr; if (!k) { @@ -192,15 +194,15 @@ uns bread_slow(struct fastbuf *f, void *b, uns l, uns check) total += k; } if (check && total && l) - bthrow(f, "fb.read", "breadb: short read"); + bthrow(f, "eof", "breadb: short read"); return total; } -void bwrite_slow(struct fastbuf *f, const void *b, uns l) +void bwrite_slow(struct fastbuf *f, const void *b, uint l) { while (l) { - uns k = f->bufend - f->bptr; + uint k = f->bufend - f->bptr; if (!k) { @@ -216,19 +218,19 @@ void bwrite_slow(struct fastbuf *f, const void *b, uns l) } } -void bbcopy_slow(struct fastbuf *f, struct fastbuf *t, uns l) +void bbcopy_slow(struct fastbuf *f, struct fastbuf *t, uint l) { while (l) { byte *fptr, *tptr; - uns favail, tavail, n; + uint favail, tavail, n; favail = bdirect_read_prepare(f, &fptr); if (!favail) { if (l == ~0U) return; - bthrow(f, "fb.read", "bbcopy: source exhausted"); + bthrow(f, "eof", "bbcopy: source exhausted"); } tavail = bdirect_write_prepare(t, &tptr); n = MIN(l, favail); @@ -241,7 +243,7 @@ void bbcopy_slow(struct fastbuf *f, struct fastbuf *t, uns l) } } -int bconfig(struct fastbuf *f, uns item, int value) +int bconfig(struct fastbuf *f, uint item, int value) { return (f->config && !(f->flags & FB_DEAD)) ? f->config(f, item, value) : -1; } @@ -252,12 +254,12 @@ void brewind(struct fastbuf *f) bsetpos(f, 0); } -int bskip_slow(struct fastbuf *f, uns len) +int bskip_slow(struct fastbuf *f, uint len) { while (len) { byte *buf; - uns l = bdirect_read_prepare(f, &buf); + uint l = bdirect_read_prepare(f, &buf); if (!l) return 0; l = MIN(l, len); @@ -297,7 +299,7 @@ static void fb_res_free(struct resource *r) bclose(f); } -static void fb_res_dump(struct resource *r, uns indent UNUSED) +static void fb_res_dump(struct resource *r, uint indent UNUSED) { struct fastbuf *f = r->priv; printf(" name=%s\n", f->name);