aboutsummaryrefslogtreecommitdiff
path: root/lib/io/src/get_line.c
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-09 13:43:50 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2023-06-09 13:43:50 +0200
commit9a4110f3c205107a3a48a0e48b760abf3cd1f3bc (patch)
tree0d89aec7c431487ebeb1254a36194acd0f837ee3 /lib/io/src/get_line.c
parent5b1a81160a6d0e63ab1360e8777009b913464d89 (diff)
libio: eliminate direct access of the interal buffer
Instead, go through helper functions, which in a next step can be moved inside the implementation. Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src/get_line.c')
-rw-r--r--lib/io/src/get_line.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/io/src/get_line.c b/lib/io/src/get_line.c
index c764d04..a939a6c 100644
--- a/lib/io/src/get_line.c
+++ b/lib/io/src/get_line.c
@@ -46,12 +46,14 @@ int istream_get_line(istream_t *strm, char **out,
for (;;) {
bool have_line = false;
- size_t i, count;
+ size_t i, count, avail;
+ const sqfs_u8 *ptr;
+ int ret;
- if (istream_precache(strm))
+ ret = istream_get_buffered_data(strm, &ptr, &avail);
+ if (ret < 0)
goto fail_free;
-
- if (strm->buffer_used == 0) {
+ if (ret > 0) {
if (line_len == 0)
goto out_eof;
@@ -62,12 +64,12 @@ int istream_get_line(istream_t *strm, char **out,
goto out_eof;
}
- for (i = 0; i < strm->buffer_used; ++i) {
- if (strm->buffer[i] == '\n')
+ for (i = 0; i < avail; ++i) {
+ if (ptr[i] == '\n')
break;
}
- if (i < strm->buffer_used) {
+ if (i < avail) {
count = i++;
have_line = true;
} else {
@@ -79,12 +81,12 @@ int istream_get_line(istream_t *strm, char **out,
goto fail_errno;
line = new;
- memcpy(line + line_len, strm->buffer, count);
+ memcpy(line + line_len, ptr, count);
line_len += count;
line[line_len] = '\0';
- strm->buffer += i;
- strm->buffer_used -= i;
+ if (istream_advance_buffer(strm, i))
+ goto fail_free;
if (have_line) {
if (line_len > 0 && line[line_len - 1] == '\r')