X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffastbuf.h;h=d831ed36153a877f27d0cf5f9cb85d90ac615604;hb=91373ee6489fbe08db12bef2cf6df704b31e1378;hp=f1f0239ae8dac3177855a5919502d287e823353f;hpb=417d2511bb77568e041fef8ea14406b265124066;p=libucw.git diff --git a/lib/fastbuf.h b/lib/fastbuf.h index f1f0239a..d831ed36 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -43,6 +43,7 @@ struct fastbuf { sh_off_t pos; /* Position of buffer start in the file */ sh_off_t fdpos; /* Current position in the non-buffered file */ int fd; /* File descriptor, -1 if not a real file */ + int is_temp_file; /* Is a temporary file, delete on close */ void *lldata; /* Data private to access functions below */ void *llpos; /* ... continued ... */ int (*refill)(struct fastbuf *); /* Get a buffer with new data */ @@ -267,7 +268,7 @@ static inline void bput5(struct fastbuf *f, u64 l) bput5_slow(f, l); } -uns bread_slow(struct fastbuf *f, void *b, uns l); +uns bread_slow(struct fastbuf *f, void *b, uns l, uns check); static inline uns bread(struct fastbuf *f, void *b, uns l) { if (f->bptr + l <= f->bstop) @@ -277,7 +278,19 @@ static inline uns bread(struct fastbuf *f, void *b, uns l) return l; } else - return bread_slow(f, b, l); + return bread_slow(f, b, l, 0); +} + +static inline uns breadb(struct fastbuf *f, void *b, uns l) +{ + if (f->bptr + l <= f->bstop) + { + memcpy(b, f->bptr, l); + f->bptr += l; + return l; + } + else + return bread_slow(f, b, l, 1); } void bwrite_slow(struct fastbuf *f, void *b, uns l); @@ -293,6 +306,7 @@ static inline void bwrite(struct fastbuf *f, void *b, uns l) } byte *bgets(struct fastbuf *f, byte *b, uns l); /* Non-std */ +byte *bgets0(struct fastbuf *f, byte *b, uns l); static inline void bputs(struct fastbuf *f, byte *b) @@ -300,6 +314,12 @@ bputs(struct fastbuf *f, byte *b) bwrite(f, b, strlen(b)); } +static inline void +bputs0(struct fastbuf *f, byte *b) +{ + bwrite(f, b, strlen(b)+1); +} + static inline void bputsn(struct fastbuf *f, byte *b) {