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>
This commit is contained in:
parent
7f16bfca9f
commit
e6c290c3d1
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue