110 lines
2.2 KiB
C
110 lines
2.2 KiB
C
#ifndef BH_IO_H
|
|
#define BH_IO_H
|
|
|
|
#include "bh.h"
|
|
|
|
#define BH_IO_ERROR 0x0001
|
|
#define BH_IO_EOF 0x0002
|
|
|
|
#define BH_IO_READ 0x0001
|
|
#define BH_IO_WRITE 0x0002
|
|
#define BH_IO_READ_WRITE (BH_IO_READ | BH_IO_WRITE)
|
|
#define BH_IO_OPEN 0x0000
|
|
#define BH_IO_CREATE 0x0100
|
|
#define BH_IO_APPEND 0x0200
|
|
#define BH_IO_TRUNCATE 0x0300
|
|
#define BH_IO_MASK 0xFF00
|
|
|
|
|
|
#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 */
|