Skip to content

Commit

Permalink
added uncompress2
Browse files Browse the repository at this point in the history
  • Loading branch information
vladtepesch committed Feb 20, 2020
1 parent e48d8ba commit ccff20b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 9 additions & 4 deletions miniz.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,19 +552,18 @@ int mz_inflateEnd(mz_streamp pStream)
}
return MZ_OK;
}

int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len)
{
mz_stream stream;
int status;
memset(&stream, 0, sizeof(stream));

/* In case mz_ulong is 64-bits (argh I hate longs). */
if ((source_len | *pDest_len) > 0xFFFFFFFFU)
if ((*pSource_len | *pDest_len) > 0xFFFFFFFFU)
return MZ_PARAM_ERROR;

stream.next_in = pSource;
stream.avail_in = (mz_uint32)source_len;
stream.avail_in = (mz_uint32)*pSource_len;
stream.next_out = pDest;
stream.avail_out = (mz_uint32)*pDest_len;

Expand All @@ -573,6 +572,7 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
return status;

status = mz_inflate(&stream, MZ_FINISH);
*pSource_len = *pSource_len - stream.avail_in;
if (status != MZ_STREAM_END)
{
mz_inflateEnd(&stream);
Expand All @@ -583,6 +583,11 @@ int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char
return mz_inflateEnd(&stream);
}

int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len)
{
return mz_uncompress2(pDest, pDest_len, pSource, &source_len);
}

const char *mz_error(int err)
{
static struct
Expand Down
2 changes: 2 additions & 0 deletions miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ MINIZ_EXPORT int mz_inflateEnd(mz_streamp pStream);
/* Single-call decompression. */
/* Returns MZ_OK on success, or one of the error codes from mz_inflate() on failure. */
MINIZ_EXPORT int mz_uncompress(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong source_len);
MINIZ_EXPORT int mz_uncompress2(unsigned char *pDest, mz_ulong *pDest_len, const unsigned char *pSource, mz_ulong *pSource_len);

/* Returns a string description of the specified error code, or NULL if the error code is invalid. */
MINIZ_EXPORT const char *mz_error(int err);
Expand Down Expand Up @@ -453,6 +454,7 @@ typedef void *const voidpc;
#define inflate mz_inflate
#define inflateEnd mz_inflateEnd
#define uncompress mz_uncompress
#define uncompress2 mz_uncompress2
#define crc32 mz_crc32
#define adler32 mz_adler32
#define MAX_WBITS 15
Expand Down

0 comments on commit ccff20b

Please sign in to comment.