lib/uzlib: Add a source_read_data var to pass to source_read_cb.

For better abstraction for users of this API.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/11905/head
Jim Mussared 2023-06-29 11:56:08 +10:00 zatwierdzone przez Damien George
rodzic 7f16bfca9f
commit e6c290c3d1
3 zmienionych plików z 6 dodań i 3 usunięć

Wyświetl plik

@ -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 read next byte using it. (Note: the callback can also update ->source
and ->source_limit). */ and ->source_limit). */
if (d->source_read_cb && !d->eof) { 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) { if (val >= 0) {
return (unsigned char)val; return (unsigned char)val;
} }

Wyświetl plik

@ -84,7 +84,8 @@ typedef struct _uzlib_uncomp_t {
also return -1 in case of EOF (or irrecoverable error). Note that also return -1 in case of EOF (or irrecoverable error). Note that
besides returning the next byte, it may also update source and besides returning the next byte, it may also update source and
source_limit fields, thus allowing for buffered operation. */ 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 tag;
unsigned int bitcount; unsigned int bitcount;

Wyświetl plik

@ -45,7 +45,8 @@ typedef struct _gz_stream_t {
static gz_stream_t gz_stream SECTION_NOZERO_BSS; 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)); int n = gz_stream.stream_read(gz_stream.stream_data, gz_stream.buf, sizeof(gz_stream.buf));
if (n < 0) { if (n < 0) {
// Stream error // Stream error
@ -76,6 +77,7 @@ int gz_stream_init_from_stream(void *stream_data, stream_read_t stream_read) {
gz_stream.stream_read = stream_read; gz_stream.stream_read = stream_read;
memset(&gz_stream.decomp, 0, sizeof(gz_stream.decomp)); 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; gz_stream.decomp.source_read_cb = gz_stream_read_src;
int header_wbits; int header_wbits;