From ad1691aa33cfc1b1558ce10e93552d0eb1cdcd63 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sat, 10 Jun 2023 17:51:03 +0200 Subject: libio: add desired read size to istream_get_buffered_data This properly maps to all of our use cases and makes istream_precache obsolete. Signed-off-by: David Oberhollenzer --- include/io/istream.h | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'include/io') diff --git a/include/io/istream.h b/include/io/istream.h index f091aa1..8edd61d 100644 --- a/include/io/istream.h +++ b/include/io/istream.h @@ -81,24 +81,6 @@ SQFS_INTERNAL int istream_get_line(istream_t *strm, char **out, */ SQFS_INTERNAL sqfs_s32 istream_read(istream_t *strm, void *data, size_t size); -/** - * @brief Adjust and refill the internal buffer of an input stream - * - * @memberof istream_t - * - * This function resets the buffer offset of an input stream (moving any unread - * data up front if it has to) and calls an internal callback of the input - * stream to fill the rest of the buffer to the extent possible. - * - * @param strm A pointer to an input stream. - * - * @return 0 on success, -1 on failure. - */ -SQFS_INLINE int istream_precache(istream_t *strm) -{ - return strm->precache(strm); -} - /** * @brief Get the underlying filename of an input stream. * @@ -129,14 +111,17 @@ SQFS_INLINE const char *istream_get_filename(istream_t *strm) * @param strm A pointer to an istream_t implementation. * @param out Returns a pointer into an internal buffer on success. * @param size Returns the number of bytes available in the buffer. + * @param want A number of bytes that the reader would like to have. If there is + * less than this available, the implementation can choose to do a + * blocking precache. * * @return Zero on success, a negative error code on failure, * a postive number on EOF. */ SQFS_INLINE int istream_get_buffered_data(istream_t *strm, const sqfs_u8 **out, - size_t *size) + size_t *size, size_t want) { - if (strm->buffer_used == 0) { + if (strm->buffer_used == 0 || strm->buffer_used < want) { int ret = strm->precache(strm); if (ret) return ret; -- cgit v1.2.3