diff options
| author | Mikhail Romanko <me@blankhex.com> | 2024-07-08 22:25:02 +0300 |
|---|---|---|
| committer | Mikhail Romanko <me@blankhex.com> | 2024-07-09 11:23:46 +0300 |
| commit | 785070798c661de51e7485a6d72bec472ed480c2 (patch) | |
| tree | a31de9e504d7811d60be131e79f9ce3ec7984922 /src/file_posix.c | |
| parent | ebb78a48022d8c84bfc8b9c580918e47631e198e (diff) | |
| download | bhlib-old-785070798c661de51e7485a6d72bec472ed480c2.tar.gz | |
Implements peek buffer on top of the raw io read (with small storage
optimization). Hides implementation details of the file/buffer.
Diffstat (limited to 'src/file_posix.c')
| -rw-r--r-- | src/file_posix.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/file_posix.c b/src/file_posix.c index e6915a5..9b61c01 100644 --- a/src/file_posix.c +++ b/src/file_posix.c @@ -19,7 +19,7 @@ static const bh_io_table_t bh_file_table = { (bh_off_t (*)(struct bh_io_s *)) bh_file_tell_base, (bh_off_t (*)(struct bh_io_s *)) bh_file_available_base, (void (*)(struct bh_io_s *)) bh_file_clear_base, - (void (*)(struct bh_io_s *)) bh_file_destroy + (void (*)(struct bh_io_s *)) bh_file_destroy_base }; bh_file_t *bh_file_new(const char *path) @@ -38,12 +38,6 @@ bh_file_t *bh_file_new(const char *path) return result; } -void bh_file_free(bh_file_t *file) -{ - bh_file_destroy(file); - free(file); -} - int bh_file_init(bh_file_t *file, const char *path) { @@ -51,8 +45,8 @@ int bh_file_init(bh_file_t *file, if (!path) return BH_INVALID; - /* Initialize base io object */ - bh_io_init(&file->base, &bh_file_table); + /* Initialize underlying io object */ + bh_io_init(&file->base, &bh_file_table, 1); /* Initialize file io object */ file->handle = -1; @@ -62,11 +56,12 @@ int bh_file_init(bh_file_t *file, return BH_OK; } -void bh_file_destroy(bh_file_t *file) +void bh_file_destroy_base(bh_file_t *file) { /* Close the file */ bh_file_close(file); free(file->path); + bh_io_destroy_base(&file->base); } int bh_file_open_base(bh_file_t *file, |
