diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-04 20:26:14 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-05 09:16:39 +0200 |
commit | 1370963723917eed6c93e28c9970a2b27be57ea4 (patch) | |
tree | 14c6e45fc1a4ccd1721823d65edd8a892135e23d /lib/io/src/win32 | |
parent | 8af4ee6f415fe316894e4423235dfc4ee70d8cbb (diff) |
libio: remove buffer_offset from istream_t
Instead, make the buffer const, let the user adjust the pointer and
size. The offset can then be inferred in precache.
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'lib/io/src/win32')
-rw-r--r-- | lib/io/src/win32/istream.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/lib/io/src/win32/istream.c b/lib/io/src/win32/istream.c index 918b868..94c8584 100644 --- a/lib/io/src/win32/istream.c +++ b/lib/io/src/win32/istream.c @@ -23,27 +23,25 @@ static int file_precache(istream_t *strm) DWORD diff, actual; HANDLE hnd; - if (strm->buffer_offset >= strm->buffer_used) { - strm->buffer_offset = 0; - strm->buffer_used = 0; - } else if (strm->buffer_offset > 0) { - memmove(strm->buffer, - strm->buffer + strm->buffer_offset, - strm->buffer_used - strm->buffer_offset); - - strm->buffer_used -= strm->buffer_offset; - strm->buffer_offset = 0; - } - if (strm->eof) return 0; + assert(strm->buffer >= file->buffer); + assert(strm->buffer <= (file->buffer + BUFSZ)); + assert(strm->buffer_used <= BUFSZ); + assert((size_t)(strm->buffer - file->buffer) <= + (BUFSZ - strm->buffer_used)); + + if (strm->buffer_used > 0) + memmove(file->buffer, strm->buffer, strm->buffer_used); + + strm->buffer = file->buffer; hnd = file->path == NULL ? GetStdHandle(STD_INPUT_HANDLE) : file->hnd; while (strm->buffer_used < sizeof(file->buffer)) { diff = sizeof(file->buffer) - strm->buffer_used; - if (!ReadFile(hnd, strm->buffer + strm->buffer_used, + if (!ReadFile(hnd, file->buffer + strm->buffer_used, diff, &actual, NULL)) { DWORD error = GetLastError(); |