aboutsummaryrefslogtreecommitdiff
path: root/include/bh/io.h
blob: cee0834805e7bc27f09699d1fcf1117d31c24ed6 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef BH_IO_H
#define BH_IO_H

#include "bh.h"

#define BH_IO_ERROR         0x0001
#define BH_IO_EOF           0x0002

#define BH_IO_NONE          0x0000
#define BH_IO_READ          0x0001
#define BH_IO_WRITE         0x0002
#define BH_IO_READ_WRITE    (BH_IO_READ | BH_IO_WRITE)

#define BH_IO_APPEND        0x0010
#define BH_IO_TRUNCATE      0x0020
#define BH_IO_CREATE        0x0040
#define BH_IO_OPEN          0x0080

#define BH_IO_SET           0x0000
#define BH_IO_CURRENT       0x0001
#define BH_IO_END           0x0002

#define BH_IO_CAST(x) \
    ((bh_io_t *)(x))

struct bh_io_s;

typedef struct bh_io_table_s
{
    int (*open)(struct bh_io_s *io,
                int mode);

    void (*close)(struct bh_io_s *io);

    int (*is_open)(struct bh_io_s *io);

    size_t (*read)(struct bh_io_s *io,
                   char *data,
                   size_t size);

    size_t (*write)(struct bh_io_s *io,
                    const char *data,
                    size_t size);

    void (*flush)(struct bh_io_s *io);

    int (*seek)(struct bh_io_s *io,
                bh_off_t offset,
                int dir);

    bh_off_t (*size)(struct bh_io_s *io);

    bh_off_t (*tell)(struct bh_io_s *io);

    bh_off_t (*available)(struct bh_io_s *io);

    void (*clear)(struct bh_io_s *io);

    void (*destroy)(struct bh_io_s *io);
} bh_io_table_t;

typedef struct bh_io_s
{
    const bh_io_table_t *table;
    int flags;
} bh_io_t;

bh_io_t *bh_io_new(bh_io_table_t *table,
                   size_t size);

void bh_io_free(bh_io_t *io);

int bh_io_open(bh_io_t *io,
               int mode);

void bh_io_close(bh_io_t *io);

int bh_io_is_open(bh_io_t *io);

size_t bh_io_read(bh_io_t *io,
                  char *data,
                  size_t size);


size_t bh_io_write(bh_io_t *io,
                   const char* data,
                   size_t size);

void bh_io_flush(bh_io_t *io);


int bh_io_seek(bh_io_t *io,
               bh_off_t offset,
               int dir);

bh_off_t bh_io_size(bh_io_t *io);

bh_off_t bh_io_tell(bh_io_t *io);


bh_off_t bh_io_available(bh_io_t *io);

int bh_io_error(bh_io_t *io);

int bh_io_eof(bh_io_t *io);

void bh_io_clear(bh_io_t *io);

#endif /* BH_IO_H */