diff options
Diffstat (limited to 'src/io.c')
| -rw-r--r-- | src/io.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/src/io.c b/src/io.c new file mode 100644 index 0000000..e4d7833 --- /dev/null +++ b/src/io.c @@ -0,0 +1,83 @@ +#include <bh/internal/io.h> +#include <stdlib.h> + +bh_io_t *bh_io_new(bh_io_table_t *table, + size_t size) +{ + bh_io_t *result; + + result = malloc(size); + if (result) + bh_io_init(result, table); + + return result; +} + +void bh_io_free(bh_io_t *io) +{ + bh_io_destroy(io); + free(io); +} + +void bh_io_init(bh_io_t *io, + bh_io_table_t *table) +{ + io->table = table; + io->flags = 0; +} + +void bh_io_destroy(bh_io_t *io) +{ + io->table->destroy(io); +} + +size_t bh_io_read(bh_io_t *io, + char *data, + size_t size) +{ + return io->table->read(io, data, size); +} + +size_t bh_io_write(bh_io_t *io, + const char* data, + size_t size) +{ + return io->table->write(io, data, size); +} + +void bh_io_flush(bh_io_t *io) +{ + io->table->flush(io); +} + +void bh_io_seek(bh_io_t *io, + bh_off_t offset, + int dir) +{ + io->table->seek(io, offset, dir); +} + +bh_off_t bh_io_tell(bh_io_t *io) +{ + return io->table->tell(io); +} + +bh_off_t bh_io_available(bh_io_t *io) +{ + return io->table->available(io); +} + +int bh_io_error(bh_io_t *io) +{ + return (io->flags & BH_IO_ERROR) > 0; +} + +int bh_io_eof(bh_io_t *io) +{ + return (io->flags & BH_IO_EOF) > 0; +} + +void bh_io_clear(bh_io_t *io) +{ + io->table->clear(io); +} |
