2024-06-03 22:11:05 +03:00
|
|
|
#ifndef BH_IO_H
|
|
|
|
|
#define BH_IO_H
|
2024-04-23 23:45:43 +03:00
|
|
|
|
|
|
|
|
#include "bh.h"
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
#define BH_IO_ERROR 0x0001
|
|
|
|
|
#define BH_IO_EOF 0x0002
|
2024-07-08 22:25:02 +03:00
|
|
|
#define BH_IO_UNIFIED 0x0004
|
2024-06-03 22:11:05 +03:00
|
|
|
|
2024-06-08 12:06:56 +03:00
|
|
|
#define BH_IO_NONE 0x0000
|
2024-06-03 22:11:05 +03:00
|
|
|
#define BH_IO_READ 0x0001
|
|
|
|
|
#define BH_IO_WRITE 0x0002
|
|
|
|
|
#define BH_IO_READ_WRITE (BH_IO_READ | BH_IO_WRITE)
|
|
|
|
|
|
2024-06-08 12:06:56 +03:00
|
|
|
#define BH_IO_APPEND 0x0010
|
|
|
|
|
#define BH_IO_TRUNCATE 0x0020
|
|
|
|
|
#define BH_IO_CREATE 0x0040
|
|
|
|
|
#define BH_IO_OPEN 0x0080
|
2024-06-03 22:11:05 +03:00
|
|
|
|
|
|
|
|
#define BH_IO_SET 0x0000
|
|
|
|
|
#define BH_IO_CURRENT 0x0001
|
|
|
|
|
#define BH_IO_END 0x0002
|
2024-04-23 23:45:43 +03:00
|
|
|
|
|
|
|
|
#define BH_IO_CAST(x) \
|
|
|
|
|
((bh_io_t *)(x))
|
|
|
|
|
|
|
|
|
|
struct bh_io_s;
|
|
|
|
|
|
|
|
|
|
typedef struct bh_io_table_s
|
|
|
|
|
{
|
2024-06-03 22:11:05 +03:00
|
|
|
int (*open)(struct bh_io_s *io,
|
|
|
|
|
int mode);
|
|
|
|
|
|
|
|
|
|
void (*close)(struct bh_io_s *io);
|
|
|
|
|
|
|
|
|
|
int (*is_open)(struct bh_io_s *io);
|
|
|
|
|
|
2024-04-23 23:45:43 +03:00
|
|
|
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);
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
int (*seek)(struct bh_io_s *io,
|
|
|
|
|
bh_off_t offset,
|
|
|
|
|
int dir);
|
|
|
|
|
|
|
|
|
|
bh_off_t (*size)(struct bh_io_s *io);
|
2024-04-23 23:45:43 +03:00
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
2024-06-03 22:11:05 +03:00
|
|
|
const bh_io_table_t *table;
|
2024-04-23 23:45:43 +03:00
|
|
|
int flags;
|
2024-07-08 22:25:02 +03:00
|
|
|
struct
|
|
|
|
|
{
|
|
|
|
|
char *data;
|
|
|
|
|
size_t head;
|
|
|
|
|
size_t tail;
|
|
|
|
|
size_t size;
|
|
|
|
|
size_t capacity;
|
|
|
|
|
} buffer;
|
2024-04-23 23:45:43 +03:00
|
|
|
} bh_io_t;
|
|
|
|
|
|
2024-07-08 22:25:02 +03:00
|
|
|
void bh_io_destroy_base(bh_io_t *io);
|
|
|
|
|
|
|
|
|
|
bh_io_t *bh_io_new(const bh_io_table_t *table,
|
|
|
|
|
size_t size,
|
|
|
|
|
int unified);
|
2024-04-23 23:45:43 +03:00
|
|
|
|
|
|
|
|
void bh_io_free(bh_io_t *io);
|
|
|
|
|
|
2024-07-08 22:25:02 +03:00
|
|
|
void bh_io_init(bh_io_t *io,
|
|
|
|
|
const bh_io_table_t *table,
|
|
|
|
|
int unified);
|
|
|
|
|
|
|
|
|
|
void bh_io_destroy(bh_io_t *io);
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
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);
|
|
|
|
|
|
2024-04-23 23:45:43 +03:00
|
|
|
size_t bh_io_read(bh_io_t *io,
|
|
|
|
|
char *data,
|
|
|
|
|
size_t size);
|
|
|
|
|
|
2024-07-08 22:25:02 +03:00
|
|
|
size_t bh_io_peek(bh_io_t *io,
|
|
|
|
|
char *data,
|
|
|
|
|
size_t size);
|
2024-06-03 22:11:05 +03:00
|
|
|
|
2024-04-23 23:45:43 +03:00
|
|
|
size_t bh_io_write(bh_io_t *io,
|
|
|
|
|
const char* data,
|
|
|
|
|
size_t size);
|
|
|
|
|
|
|
|
|
|
void bh_io_flush(bh_io_t *io);
|
|
|
|
|
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
int bh_io_seek(bh_io_t *io,
|
|
|
|
|
bh_off_t offset,
|
|
|
|
|
int dir);
|
|
|
|
|
|
|
|
|
|
bh_off_t bh_io_size(bh_io_t *io);
|
|
|
|
|
|
2024-04-23 23:45:43 +03:00
|
|
|
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);
|
|
|
|
|
|
2024-06-03 22:11:05 +03:00
|
|
|
#endif /* BH_IO_H */
|