aboutsummaryrefslogtreecommitdiff
path: root/src/io.c
blob: e4d7833bc795c2e728b9a606068f5581129e04d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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);
}