diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-11 17:59:21 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-11 19:29:25 +0200 |
commit | c7eae87870da755586446fecb4eb30063c1d641c (patch) | |
tree | 3b8d1a7846bbe356fc1a3700b57582265760bbca /include/io | |
parent | 366ccf20745b23f1eb8554cbe17e6972271de002 (diff) |
libio: move istream buffer logic into interall callbacks
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/io')
-rw-r--r-- | include/io/istream.h | 21 |
1 files changed, 5 insertions, 16 deletions
diff --git a/include/io/istream.h b/include/io/istream.h index fca1440..8e86891 100644 --- a/include/io/istream.h +++ b/include/io/istream.h @@ -20,10 +20,10 @@ typedef struct istream_t { sqfs_object_t base; - size_t buffer_used; - const sqfs_u8 *buffer; + int (*get_buffered_data)(struct istream_t *strm, const sqfs_u8 **out, + size_t *size, size_t want); - int (*precache)(struct istream_t *strm); + void (*advance_buffer)(struct istream_t *strm, size_t count); const char *(*get_filename)(struct istream_t *strm); } istream_t; @@ -121,17 +121,7 @@ SQFS_INLINE const char *istream_get_filename(istream_t *strm) SQFS_INLINE int istream_get_buffered_data(istream_t *strm, const sqfs_u8 **out, size_t *size, size_t want) { - if (strm->buffer_used == 0 || strm->buffer_used < want) { - int ret = strm->precache(strm); - if (ret) - return ret; - if (strm->buffer_used == 0) - return 1; - } - - *out = strm->buffer; - *size = strm->buffer_used; - return 0; + return strm->get_buffered_data(strm, out, size, want); } /** @@ -148,8 +138,7 @@ SQFS_INLINE int istream_get_buffered_data(istream_t *strm, const sqfs_u8 **out, */ SQFS_INLINE void istream_advance_buffer(istream_t *strm, size_t count) { - strm->buffer += count; - strm->buffer_used -= count; + strm->advance_buffer(strm, count); } /** |