diff --git a/c/buf.c b/c/buf.c index 6000437..d3cc9a7 100644 --- a/c/buf.c +++ b/c/buf.c @@ -7,6 +7,9 @@ #include #include +#include "dtypes.h" +#include "ios.h" + #include "buf.h" struct buf *buf_new(void) { return calloc(1, sizeof(struct buf)); } @@ -28,6 +31,19 @@ char *buf_resb(struct buf *buf, size_t nbyte) return place; } +void buf_put_ios(struct buf *buf, struct ios *ios) +{ + const size_t chunksize = 512; + size_t nread; + char *chunk; + + do { + chunk = buf_resb(buf, chunksize); + nread = ios_readall(ios, chunk, chunksize); + buf->fill -= (chunksize - nread); + } while (nread); +} + void buf_putc(struct buf *buf, int c) { buf_resb(buf, 1)[0] = c; } void buf_putb(struct buf *buf, const void *bytes, size_t nbyte) diff --git a/c/buf.h b/c/buf.h index f870eb6..4a00d88 100644 --- a/c/buf.h +++ b/c/buf.h @@ -9,6 +9,7 @@ struct buf { struct buf *buf_new(void); char *buf_resb(struct buf *buf, size_t nbyte); +void buf_put_ios(struct buf *buf, struct ios *ios); void buf_putc(struct buf *buf, int c); void buf_putb(struct buf *buf, const void *bytes, size_t nbyte); void buf_puts(struct buf *buf, const char *s);