X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Ffastbuf.h;h=2948830ee4e0331e305a9c5a9ceb66486ca738db;hb=89556b90f1afb9b7ebe247c05721e0a04a7232c0;hp=eb30d09cf0a38d98faa40799f49b290cd11e6c29;hpb=79eebb222ecee1db69c22fe97e359cbcbb12fa8e;p=libucw.git diff --git a/lib/fastbuf.h b/lib/fastbuf.h index eb30d09c..2948830e 100644 --- a/lib/fastbuf.h +++ b/lib/fastbuf.h @@ -11,6 +11,8 @@ #include #endif +#include + #include "lib/unaligned.h" /* @@ -57,6 +59,7 @@ struct fastbuf { /* FastIO on standard files */ struct fastbuf *bopen(byte *name, uns mode, uns buffer); +struct fastbuf *bopen_tmp(uns buffer); struct fastbuf *bfdopen(int fd, uns buffer); void bbcopy(struct fastbuf *f, struct fastbuf *t, uns l); @@ -89,13 +92,13 @@ static inline int bpeekc(struct fastbuf *f) return (f->bptr < f->bstop) ? (int) *f->bptr : bpeekc_slow(f); } -static inline void bungetc(struct fastbuf *f, byte c) +static inline void bungetc(struct fastbuf *f) { - *--f->bptr = c; + f->bptr--; } -void bputc_slow(struct fastbuf *f, byte c); -static inline void bputc(struct fastbuf *f, byte c) +void bputc_slow(struct fastbuf *f, uns c); +static inline void bputc(struct fastbuf *f, uns c) { if (f->bptr < f->bufend) *f->bptr++ = c; @@ -103,10 +106,10 @@ static inline void bputc(struct fastbuf *f, byte c) bputc_slow(f, c); } -word bgetw_slow(struct fastbuf *f); -static inline word bgetw(struct fastbuf *f) +int bgetw_slow(struct fastbuf *f); +static inline int bgetw(struct fastbuf *f) { - word w; + int w; if (f->bptr + 2 <= f->bstop) { w = GET_U16(f->bptr); @@ -159,8 +162,8 @@ static inline u64 bget5(struct fastbuf *f) return bget5_slow(f); } -void bputw_slow(struct fastbuf *f, word w); -static inline void bputw(struct fastbuf *f, word w) +void bputw_slow(struct fastbuf *f, uns w); +static inline void bputw(struct fastbuf *f, uns w) { if (f->bptr + 2 <= f->bufend) { @@ -266,6 +269,16 @@ bputsn(struct fastbuf *f, byte *b) bputc(f, '\n'); } +/* I/O on addr_int_t */ + +#ifdef CPU_64BIT_POINTERS +#define bputa(x,p) bputq(x,p) +#define bgeta(x) bgetq(x) +#else +#define bputa(x,p) bputl(x,p) +#define bgeta(x) bgetl(x) +#endif + /* Direct I/O on buffers */ int bdirect_read(struct fastbuf *f, byte **buf);