Skip to content

Commit

Permalink
lib/uzlib: Add a source_read_data var to pass to source_read_cb.
Browse files Browse the repository at this point in the history
For better abstraction for users of this API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
  • Loading branch information
jimmo authored and dpgeorge committed Jul 21, 2023
1 parent 7f16bfc commit e6c290c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/uzlib/tinflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ unsigned char uzlib_get_byte(uzlib_uncomp_t *d)
read next byte using it. (Note: the callback can also update ->source
and ->source_limit). */
if (d->source_read_cb && !d->eof) {
int val = d->source_read_cb(d);
int val = d->source_read_cb(d->source_read_data);
if (val >= 0) {
return (unsigned char)val;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/uzlib/uzlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ typedef struct _uzlib_uncomp_t {
also return -1 in case of EOF (or irrecoverable error). Note that
besides returning the next byte, it may also update source and
source_limit fields, thus allowing for buffered operation. */
int (*source_read_cb)(struct _uzlib_uncomp_t *uncomp);
void *source_read_data;
int (*source_read_cb)(void *);

unsigned int tag;
unsigned int bitcount;
Expand Down
4 changes: 3 additions & 1 deletion ports/stm32/mboot/gzstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ typedef struct _gz_stream_t {

static gz_stream_t gz_stream SECTION_NOZERO_BSS;

static int gz_stream_read_src(uzlib_uncomp_t *decomp) {
static int gz_stream_read_src(void *data) {
uzlib_uncomp_t *decomp = data;
int n = gz_stream.stream_read(gz_stream.stream_data, gz_stream.buf, sizeof(gz_stream.buf));
if (n < 0) {
// Stream error
Expand Down Expand Up @@ -76,6 +77,7 @@ int gz_stream_init_from_stream(void *stream_data, stream_read_t stream_read) {
gz_stream.stream_read = stream_read;

memset(&gz_stream.decomp, 0, sizeof(gz_stream.decomp));
gz_stream.decomp.source_read_data = &gz_stream.decomp;
gz_stream.decomp.source_read_cb = gz_stream_read_src;

int header_wbits;
Expand Down

0 comments on commit e6c290c

Please sign in to comment.