Skip to content

Commit

Permalink
COMMON: Don't seek back in I/O reading functions
Browse files Browse the repository at this point in the history
  • Loading branch information
HappySeaFox committed Sep 24, 2023
1 parent d8035b3 commit 26f4a95
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 17 deletions.
13 changes: 0 additions & 13 deletions src/libsail-common/io_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,6 @@ sail_status_t sail_io_contents_into_data(struct sail_io *io, void *data) {
SAIL_CHECK_PTR(io);
SAIL_CHECK_PTR(data);

/* Save the current position. */
size_t saved_position;
SAIL_TRY(io->tell(io->stream, &saved_position));

unsigned char buffer[4096];
unsigned char *data_ptr = data;
size_t actually_read;
Expand All @@ -126,8 +122,6 @@ sail_status_t sail_io_contents_into_data(struct sail_io *io, void *data) {
data_ptr += actually_read;
}

SAIL_TRY(io->seek(io->stream, (long)saved_position, SEEK_SET));

if (status != SAIL_ERROR_EOF) {
SAIL_LOG_ERROR("Failed to read from the I/O stream, error #%d", status);
SAIL_LOG_AND_RETURN(SAIL_ERROR_READ_IO);
Expand All @@ -142,10 +136,6 @@ sail_status_t sail_alloc_data_from_io_contents(struct sail_io *io, void **data,
SAIL_CHECK_PTR(data);
SAIL_CHECK_PTR(data_size);

/* Save the current position. */
size_t saved_position;
SAIL_TRY(io->tell(io->stream, &saved_position));

size_t data_size_local;
SAIL_TRY(sail_io_size(io, &data_size_local));

Expand All @@ -156,9 +146,6 @@ sail_status_t sail_alloc_data_from_io_contents(struct sail_io *io, void **data,
SAIL_TRY_OR_CLEANUP(io->strict_read(io->stream, data_local, data_size_local),
/* cleanup */ sail_free(data_local));

/* Seek back. */
SAIL_TRY(io->seek(io->stream, (long)saved_position, SEEK_SET));

*data = data_local;
*data_size = data_size_local;

Expand Down
6 changes: 2 additions & 4 deletions src/libsail-common/io_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,15 @@ SAIL_EXPORT sail_status_t sail_io_size(struct sail_io *io, size_t *size);

/*
* Reads the specified I/O stream until EOF into the memory buffer. Reads the stream
* from the current position and then rewinds it back (i.e. the stream must be seekable).
* The buffer must be large enough.
* from the current position. The buffer must be large enough.
*
* Returns SAIL_OK on success.
*/
SAIL_EXPORT sail_status_t sail_io_contents_into_data(struct sail_io *io, void *data);

/*
* Allocates a memory buffer and reads the specified I/O stream until EOF into it.
* Reads the stream from the current position and then rewinds it back (i.e. the stream
* must be seekable).
* Reads the stream from the current position.
*
* The size of the memory buffer is stored in 'data_size'.
*
Expand Down

0 comments on commit 26f4a95

Please sign in to comment.