mirror of
https://github.com/zlib-ng/minizip-ng
synced 2025-03-28 21:13:18 +00:00
Added additional error codes to aid in debugging.
This commit is contained in:
parent
71027dc8fb
commit
05e03cad8e
@ -142,6 +142,7 @@ set(MINIZIP_PUBLIC_HEADERS
|
||||
mz_strm_buf.h
|
||||
mz_strm_crc32.h
|
||||
mz_strm_mem.h
|
||||
mz_strm_split.h
|
||||
mz_strm_os.h
|
||||
mz_zip.h
|
||||
mz_zip_rw.h)
|
||||
|
8
mz.h
8
mz.h
@ -28,8 +28,10 @@ extern "C" {
|
||||
#define MZ_MEM_ERROR (-4) // zlib
|
||||
#define MZ_BUF_ERROR (-5) // zlib
|
||||
#define MZ_VERSION_ERROR (-6) // zlib
|
||||
|
||||
#define MZ_END_OF_LIST (-100)
|
||||
#define MZ_END_OF_STREAM (-101)
|
||||
|
||||
#define MZ_PARAM_ERROR (-102)
|
||||
#define MZ_FORMAT_ERROR (-103)
|
||||
#define MZ_INTERNAL_ERROR (-104)
|
||||
@ -39,6 +41,12 @@ extern "C" {
|
||||
#define MZ_PASSWORD_ERROR (-108)
|
||||
#define MZ_SUPPORT_ERROR (-109)
|
||||
#define MZ_HASH_ERROR (-110)
|
||||
#define MZ_OPEN_ERROR (-111)
|
||||
#define MZ_CLOSE_ERROR (-112)
|
||||
#define MZ_SEEK_ERROR (-113)
|
||||
#define MZ_TELL_ERROR (-114)
|
||||
#define MZ_READ_ERROR (-115)
|
||||
#define MZ_WRITE_ERROR (-116)
|
||||
|
||||
// MZ_OPEN
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
|
@ -109,7 +109,7 @@ static int32_t mz_stream_buffered_flush(void *stream, int32_t *written)
|
||||
buffered->writebuf + (bytes_to_write - bytes_left_to_write), bytes_left_to_write);
|
||||
|
||||
if (bytes_written != bytes_left_to_write)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
buffered->writebuf_misses += 1;
|
||||
|
||||
@ -201,6 +201,7 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t bytes_to_copy = 0;
|
||||
int32_t bytes_used = 0;
|
||||
int32_t bytes_flushed = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
mz_stream_buffered_print(stream, "write [size %ld len %d pos %lld]\n",
|
||||
@ -216,8 +217,9 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
mz_stream_buffered_print(stream, "switch from read to write [%lld]\n", buffered->position);
|
||||
|
||||
if (mz_stream_seek(buffered->stream.base, buffered->position, MZ_SEEK_SET) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
err = mz_stream_seek(buffered->stream.base, buffered->position, MZ_SEEK_SET);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
}
|
||||
|
||||
while (bytes_left_to_write > 0)
|
||||
@ -231,8 +233,9 @@ int32_t mz_stream_buffered_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
if (bytes_to_copy == 0)
|
||||
{
|
||||
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
err = mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
if (bytes_flushed == 0)
|
||||
return 0;
|
||||
|
||||
@ -276,6 +279,7 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_buffered *buffered = (mz_stream_buffered *)stream;
|
||||
int32_t bytes_flushed = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
mz_stream_buffered_print(stream, "seek [origin %d offset %llu pos %lld]\n", origin, offset, buffered->position);
|
||||
|
||||
@ -299,8 +303,9 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
err = mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
buffered->position = offset;
|
||||
break;
|
||||
@ -327,8 +332,9 @@ int32_t mz_stream_buffered_seek(void *stream, int64_t offset, int32_t origin)
|
||||
//offset -= (buffered->writebuf_len - buffered->writebuf_pos);
|
||||
}
|
||||
|
||||
if (mz_stream_buffered_flush(stream, &bytes_flushed) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
err = mz_stream_buffered_flush(stream, &bytes_flushed);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
break;
|
||||
|
||||
|
@ -97,7 +97,7 @@ int32_t mz_stream_bzip_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
|
||||
if (bzip->error != BZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
bzip->initialized = 1;
|
||||
bzip->stream_end = 0;
|
||||
@ -109,7 +109,7 @@ int32_t mz_stream_bzip_is_open(void *stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
if (bzip->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ static int32_t mz_stream_bzip_flush(void *stream)
|
||||
{
|
||||
mz_stream_bzip *bzip = (mz_stream_bzip *)stream;
|
||||
if (mz_stream_write(bzip->stream.base, bzip->buffer, bzip->buffer_len) != bzip->buffer_len)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -219,11 +219,9 @@ static int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
{
|
||||
if (bzip->bzstream.avail_out == 0)
|
||||
{
|
||||
if (mz_stream_bzip_flush(bzip) != MZ_OK)
|
||||
{
|
||||
bzip->error = BZ_DATA_ERROR;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
err = mz_stream_bzip_flush(bzip);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
bzip->bzstream.avail_out = sizeof(bzip->buffer);
|
||||
bzip->bzstream.next_out = (char *)bzip->buffer;
|
||||
@ -249,7 +247,7 @@ static int32_t mz_stream_bzip_compress(void *stream, int flush)
|
||||
if (err < 0)
|
||||
{
|
||||
bzip->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
while ((bzip->bzstream.avail_in > 0) || (flush == BZ_FINISH && err == BZ_FINISH_OK));
|
||||
@ -280,7 +278,7 @@ int64_t mz_stream_bzip_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_TELL_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_seek(void *stream, int64_t offset, int32_t origin)
|
||||
@ -289,7 +287,7 @@ int32_t mz_stream_bzip_seek(void *stream, int64_t offset, int32_t origin)
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_bzip_close(void *stream)
|
||||
@ -319,7 +317,7 @@ int32_t mz_stream_bzip_close(void *stream)
|
||||
bzip->initialized = 0;
|
||||
|
||||
if (bzip->error != BZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_CLOSE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,7 @@ int32_t mz_stream_crc32_is_open(void *stream)
|
||||
{
|
||||
mz_stream_crc32 *crc32 = (mz_stream_crc32 *)stream;
|
||||
if (crc32->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ int32_t mz_stream_libcomp_open(void *stream, const char *path, int32_t mode)
|
||||
if (err == COMPRESSION_STATUS_ERROR)
|
||||
{
|
||||
libcomp->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
}
|
||||
|
||||
libcomp->initialized = 1;
|
||||
@ -107,7 +107,7 @@ int32_t mz_stream_libcomp_is_open(void *stream)
|
||||
{
|
||||
mz_stream_libcomp *libcomp = (mz_stream_libcomp *)stream;
|
||||
if (libcomp->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -198,7 +198,7 @@ static int32_t mz_stream_libcomp_flush(void *stream)
|
||||
{
|
||||
mz_stream_libcomp *libcomp = (mz_stream_libcomp *)stream;
|
||||
if (mz_stream_write(libcomp->stream.base, libcomp->buffer, libcomp->buffer_len) != libcomp->buffer_len)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -219,7 +219,7 @@ static int32_t mz_stream_libcomp_deflate(void *stream, int flush)
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
libcomp->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return err;
|
||||
}
|
||||
|
||||
libcomp->cstream.dst_size = sizeof(libcomp->buffer);
|
||||
@ -242,7 +242,7 @@ static int32_t mz_stream_libcomp_deflate(void *stream, int flush)
|
||||
if (err != COMPRESSION_STATUS_OK)
|
||||
{
|
||||
libcomp->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
while ((libcomp->cstream.src_size > 0) || (flush == COMPRESSION_STREAM_FINALIZE && err == COMPRESSION_STATUS_OK));
|
||||
@ -273,7 +273,7 @@ int64_t mz_stream_libcomp_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_TELL_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_libcomp_seek(void *stream, int64_t offset, int32_t origin)
|
||||
@ -282,7 +282,7 @@ int32_t mz_stream_libcomp_seek(void *stream, int64_t offset, int32_t origin)
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_libcomp_close(void *stream)
|
||||
@ -311,7 +311,7 @@ int32_t mz_stream_libcomp_close(void *stream)
|
||||
libcomp->initialized = 0;
|
||||
|
||||
if (libcomp->error != Z_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_CLOSE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
lzma->lstream.avail_out = sizeof(lzma->buffer);
|
||||
|
||||
if (lzma_lzma_preset(&opt_lzma, lzma->preset))
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
memset(&filters, 0, sizeof(filters));
|
||||
|
||||
@ -128,7 +128,7 @@ int32_t mz_stream_lzma_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
|
||||
if (lzma->error != LZMA_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
lzma->initialized = 1;
|
||||
lzma->mode = mode;
|
||||
@ -139,7 +139,7 @@ int32_t mz_stream_lzma_is_open(void *stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
if (lzma->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -227,7 +227,7 @@ static int32_t mz_stream_lzma_flush(void *stream)
|
||||
{
|
||||
mz_stream_lzma *lzma = (mz_stream_lzma *)stream;
|
||||
if (mz_stream_write(lzma->stream.base, lzma->buffer, lzma->buffer_len) != lzma->buffer_len)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -244,11 +244,9 @@ static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
{
|
||||
if (lzma->lstream.avail_out == 0)
|
||||
{
|
||||
if (mz_stream_lzma_flush(lzma) != MZ_OK)
|
||||
{
|
||||
lzma->error = MZ_STREAM_ERROR;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
err = mz_stream_lzma_flush(lzma);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
lzma->lstream.avail_out = sizeof(lzma->buffer);
|
||||
lzma->lstream.next_out = lzma->buffer;
|
||||
@ -265,7 +263,7 @@ static int32_t mz_stream_lzma_code(void *stream, int32_t flush)
|
||||
if (err != LZMA_OK && err != LZMA_STREAM_END)
|
||||
{
|
||||
lzma->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_DATA_ERROR;
|
||||
}
|
||||
|
||||
lzma->buffer_len += out_bytes;
|
||||
@ -299,7 +297,7 @@ int64_t mz_stream_lzma_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_TELL_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_seek(void *stream, int64_t offset, int32_t origin)
|
||||
@ -308,7 +306,7 @@ int32_t mz_stream_lzma_seek(void *stream, int64_t offset, int32_t origin)
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_lzma_close(void *stream)
|
||||
@ -338,7 +336,7 @@ int32_t mz_stream_lzma_close(void *stream)
|
||||
lzma->initialized = 0;
|
||||
|
||||
if (lzma->error != LZMA_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_CLOSE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
@ -96,7 +96,7 @@ int32_t mz_stream_mem_is_open(void *stream)
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
if (mem->buffer == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -174,13 +174,13 @@ int32_t mz_stream_mem_seek(void *stream, int64_t offset, int32_t origin)
|
||||
new_pos = offset;
|
||||
break;
|
||||
default:
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
if (new_pos > mem->size)
|
||||
{
|
||||
if ((mem->mode & MZ_OPEN_MODE_CREATE) == 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
|
||||
mz_stream_mem_set_size(stream, (int32_t)new_pos);
|
||||
}
|
||||
@ -222,7 +222,7 @@ int32_t mz_stream_mem_get_buffer_at(void *stream, int64_t position, const void *
|
||||
{
|
||||
mz_stream_mem *mem = (mz_stream_mem *)stream;
|
||||
if (buf == NULL || position < 0 || mem->size < position || mem->buffer == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
*buf = mem->buffer + position;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
const char *mode_fopen = NULL;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if ((mode & MZ_OPEN_MODE_READWRITE) == MZ_OPEN_MODE_READ)
|
||||
mode_fopen = "rb";
|
||||
@ -91,13 +91,13 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
else if (mode & MZ_OPEN_MODE_CREATE)
|
||||
mode_fopen = "wb";
|
||||
else
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
posix->handle = fopen64(path, mode_fopen);
|
||||
if (posix->handle == NULL)
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
@ -107,7 +107,7 @@ int32_t mz_stream_os_is_open(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
if (posix->handle == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ int32_t mz_stream_os_read(void *stream, void *buf, int32_t size)
|
||||
if (read < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_READ_ERROR;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
@ -130,7 +130,7 @@ int32_t mz_stream_os_write(void *stream, const void *buf, int32_t size)
|
||||
if (written < size && ferror(posix->handle))
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
}
|
||||
return written;
|
||||
}
|
||||
@ -142,7 +142,7 @@ int64_t mz_stream_os_tell(void *stream)
|
||||
if (position == -1)
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_TELL_ERROR;
|
||||
}
|
||||
return position;
|
||||
}
|
||||
@ -164,13 +164,13 @@ int32_t mz_stream_os_seek(void *stream, int64_t offset, int32_t origin)
|
||||
fseek_origin = SEEK_SET;
|
||||
break;
|
||||
default:
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
if (fseeko64(posix->handle, offset, fseek_origin) != 0)
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
@ -188,7 +188,7 @@ int32_t mz_stream_os_close(void *stream)
|
||||
if (closed != 0)
|
||||
{
|
||||
posix->error = errno;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_CLOSE_ERROR;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
@ -79,7 +79,7 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if ((mode & MZ_OPEN_MODE_READWRITE) == MZ_OPEN_MODE_READ)
|
||||
{
|
||||
@ -98,7 +98,7 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
else
|
||||
{
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
}
|
||||
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
@ -116,7 +116,7 @@ int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
{
|
||||
win32->error = GetLastError();
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
}
|
||||
|
||||
if (mode & MZ_OPEN_MODE_APPEND)
|
||||
@ -129,7 +129,7 @@ int32_t mz_stream_os_is_open(void *stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
if (win32->handle == NULL || win32->handle == INVALID_HANDLE_VALUE)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ int32_t mz_stream_os_read(void *stream, void *buf, int32_t size)
|
||||
uint32_t read = 0;
|
||||
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
if (!ReadFile(win32->handle, buf, size, (DWORD *)&read, NULL))
|
||||
{
|
||||
@ -157,7 +157,7 @@ int32_t mz_stream_os_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t written = 0;
|
||||
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
if (!WriteFile(win32->handle, buf, size, (DWORD *)&written, NULL))
|
||||
{
|
||||
@ -182,7 +182,7 @@ static int32_t mz_stream_os_seekinternal(HANDLE handle, LARGE_INTEGER large_pos,
|
||||
pos = SetFilePointer(handle, large_pos.LowPart, &high_part, move_method);
|
||||
|
||||
if ((pos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
|
||||
if (new_pos != NULL)
|
||||
{
|
||||
@ -200,7 +200,7 @@ int64_t mz_stream_os_tell(void *stream)
|
||||
LARGE_INTEGER large_pos;
|
||||
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
large_pos.QuadPart = 0;
|
||||
|
||||
@ -214,11 +214,12 @@ int32_t mz_stream_os_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
uint32_t move_method = 0xFFFFFFFF;
|
||||
int32_t err = MZ_OK;
|
||||
LARGE_INTEGER large_pos;
|
||||
|
||||
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
switch (origin)
|
||||
{
|
||||
@ -232,15 +233,16 @@ int32_t mz_stream_os_seek(void *stream, int64_t offset, int32_t origin)
|
||||
move_method = FILE_BEGIN;
|
||||
break;
|
||||
default:
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
large_pos.QuadPart = offset;
|
||||
|
||||
if (mz_stream_os_seekinternal(win32->handle, large_pos, NULL, move_method) != MZ_OK)
|
||||
err = mz_stream_os_seekinternal(win32->handle, large_pos, NULL, move_method);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
win32->error = GetLastError();
|
||||
return MZ_STREAM_ERROR;
|
||||
return err;
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
|
@ -144,12 +144,12 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
pkcrypt->initialized = 0;
|
||||
|
||||
if (mz_stream_is_open(pkcrypt->stream.base) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
if (password == NULL)
|
||||
password = pkcrypt->password;
|
||||
if (password == NULL)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (mz_stream_crc32_get_update_func(&pkcrypt->crc32_update) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
@ -175,7 +175,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
header[i++] = mz_stream_pkcrypt_encode(stream, pkcrypt->verify2, t);
|
||||
|
||||
if (mz_stream_write(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
pkcrypt->total_out += RAND_HEAD_LEN;
|
||||
#endif
|
||||
@ -191,7 +191,7 @@ int32_t mz_stream_pkcrypt_open(void *stream, const char *path, int32_t mode)
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
if (mz_stream_read(pkcrypt->stream.base, header, RAND_HEAD_LEN) != RAND_HEAD_LEN)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_READ_ERROR;
|
||||
|
||||
for (i = 0; i < RAND_HEAD_LEN - 2; i++)
|
||||
header[i] = mz_stream_pkcrypt_decode(stream, header[i]);
|
||||
@ -216,7 +216,7 @@ int32_t mz_stream_pkcrypt_is_open(void *stream)
|
||||
{
|
||||
mz_stream_pkcrypt *pkcrypt = (mz_stream_pkcrypt *)stream;
|
||||
if (pkcrypt->initialized == 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -245,7 +245,7 @@ int32_t mz_stream_pkcrypt_write(void *stream, const void *buf, int32_t size)
|
||||
uint16_t t = 0;
|
||||
|
||||
if (size > (int32_t)sizeof(pkcrypt->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
pkcrypt->buffer[i] = mz_stream_pkcrypt_encode(stream, buf_ptr[i], t);
|
||||
|
@ -220,9 +220,9 @@ int32_t mz_stream_split_open(void *stream, const char *path, int32_t mode)
|
||||
int32_t mz_stream_split_is_open(void *stream)
|
||||
{
|
||||
mz_stream_split *split = (mz_stream_split *)stream;
|
||||
if (split->is_open == 1)
|
||||
return MZ_OK;
|
||||
return MZ_STREAM_ERROR;
|
||||
if (split->is_open != 1)
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_split_read(void *stream, void *buf, int32_t size)
|
||||
@ -299,7 +299,7 @@ int32_t mz_stream_split_write(void *stream, const void *buf, int32_t size)
|
||||
|
||||
written = mz_stream_write(split->stream.base, buf_ptr, bytes_to_write);
|
||||
if (written != bytes_to_write)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
bytes_left -= written;
|
||||
buf_ptr += written;
|
||||
|
@ -170,7 +170,7 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
wzaes->initialized = 0;
|
||||
|
||||
if (mz_stream_is_open(wzaes->stream.base) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
if (password == NULL)
|
||||
password = wzaes->password;
|
||||
@ -199,7 +199,7 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
return MZ_SUPPORT_ERROR;
|
||||
#else
|
||||
if (mz_stream_read(wzaes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_READ_ERROR;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -230,12 +230,12 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
if (mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
if (mz_stream_write(wzaes->stream.base, salt_value, salt_length) != salt_length)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
wzaes->total_out += salt_length;
|
||||
|
||||
if (mz_stream_write(wzaes->stream.base, verify, MZ_AES_PW_VERIFY_SIZE) != MZ_AES_PW_VERIFY_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
wzaes->total_out += MZ_AES_PW_VERIFY_SIZE;
|
||||
}
|
||||
@ -244,7 +244,7 @@ int32_t mz_stream_wzaes_open(void *stream, const char *path, int32_t mode)
|
||||
wzaes->total_in += salt_length;
|
||||
|
||||
if (mz_stream_read(wzaes->stream.base, verify_expected, MZ_AES_PW_VERIFY_SIZE) != MZ_AES_PW_VERIFY_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_READ_ERROR;
|
||||
|
||||
wzaes->total_in += MZ_AES_PW_VERIFY_SIZE;
|
||||
|
||||
@ -262,7 +262,7 @@ int32_t mz_stream_wzaes_is_open(void *stream)
|
||||
{
|
||||
mz_stream_wzaes *wzaes = (mz_stream_wzaes *)stream;
|
||||
if (wzaes->initialized == 0)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -327,7 +327,7 @@ int32_t mz_stream_wzaes_write(void *stream, const void *buf, int32_t size)
|
||||
if (size < 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
if (size > (int32_t)sizeof(wzaes->buffer))
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_BUF_ERROR;
|
||||
|
||||
memcpy(wzaes->buffer, buf, size);
|
||||
mz_stream_wzaes_encrypt_data(stream, (uint8_t *)wzaes->buffer, size);
|
||||
@ -362,14 +362,14 @@ int32_t mz_stream_wzaes_close(void *stream)
|
||||
if (wzaes->mode & MZ_OPEN_MODE_WRITE)
|
||||
{
|
||||
if (mz_stream_write(wzaes->stream.base, computed_hash, MZ_AES_AUTHCODE_SIZE) != MZ_AES_AUTHCODE_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
wzaes->total_out += MZ_AES_AUTHCODE_SIZE;
|
||||
}
|
||||
else if (wzaes->mode & MZ_OPEN_MODE_READ)
|
||||
{
|
||||
if (mz_stream_read(wzaes->stream.base, expected_hash, MZ_AES_AUTHCODE_SIZE) != MZ_AES_AUTHCODE_SIZE)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_READ_ERROR;
|
||||
|
||||
wzaes->total_in += MZ_AES_AUTHCODE_SIZE;
|
||||
|
||||
|
@ -115,7 +115,7 @@ int32_t mz_stream_zlib_open(void *stream, const char *path, int32_t mode)
|
||||
}
|
||||
|
||||
if (zlib->error != Z_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
|
||||
zlib->initialized = 1;
|
||||
zlib->mode = mode;
|
||||
@ -126,7 +126,7 @@ int32_t mz_stream_zlib_is_open(void *stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
if (zlib->initialized != 1)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_OPEN_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -221,7 +221,7 @@ static int32_t mz_stream_zlib_flush(void *stream)
|
||||
{
|
||||
mz_stream_zlib *zlib = (mz_stream_zlib *)stream;
|
||||
if (mz_stream_write(zlib->stream.base, zlib->buffer, zlib->buffer_len) != zlib->buffer_len)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
@ -238,11 +238,9 @@ static int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
{
|
||||
if (zlib->zstream.avail_out == 0)
|
||||
{
|
||||
if (mz_stream_zlib_flush(zlib) != MZ_OK)
|
||||
{
|
||||
zlib->error = Z_STREAM_ERROR;
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
err = mz_stream_zlib_flush(zlib);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
zlib->zstream.avail_out = sizeof(zlib->buffer);
|
||||
zlib->zstream.next_out = zlib->buffer;
|
||||
@ -264,7 +262,7 @@ static int32_t mz_stream_zlib_deflate(void *stream, int flush)
|
||||
if (err != Z_OK)
|
||||
{
|
||||
zlib->error = err;
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_DATA_ERROR;
|
||||
}
|
||||
}
|
||||
while ((zlib->zstream.avail_in > 0) || (flush == Z_FINISH && err == Z_OK));
|
||||
@ -295,7 +293,7 @@ int64_t mz_stream_zlib_tell(void *stream)
|
||||
{
|
||||
MZ_UNUSED(stream);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_TELL_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin)
|
||||
@ -304,7 +302,7 @@ int32_t mz_stream_zlib_seek(void *stream, int64_t offset, int32_t origin)
|
||||
MZ_UNUSED(offset);
|
||||
MZ_UNUSED(origin);
|
||||
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_SEEK_ERROR;
|
||||
}
|
||||
|
||||
int32_t mz_stream_zlib_close(void *stream)
|
||||
@ -335,7 +333,7 @@ int32_t mz_stream_zlib_close(void *stream)
|
||||
zlib->initialized = 0;
|
||||
|
||||
if (zlib->error != Z_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_CLOSE_ERROR;
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
|
14
mz_zip.c
14
mz_zip.c
@ -113,11 +113,13 @@ static int32_t mz_zip_search_eocd(void *stream, int64_t *central_pos)
|
||||
int32_t read_size = sizeof(buf);
|
||||
int64_t read_pos = 0;
|
||||
int32_t i = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
*central_pos = 0;
|
||||
|
||||
if (mz_stream_seek(stream, 0, MZ_SEEK_END) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
err = mz_stream_seek(stream, 0, MZ_SEEK_END);
|
||||
if (err != MZ_OK)
|
||||
return err;
|
||||
|
||||
file_size = mz_stream_tell(stream);
|
||||
|
||||
@ -267,7 +269,7 @@ static int32_t mz_zip_read_cd(void *handle)
|
||||
if (zip->comment != NULL)
|
||||
{
|
||||
if (mz_stream_read(zip->stream, zip->comment, comment_size) != comment_size)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_READ_ERROR;
|
||||
zip->comment[comment_size] = 0;
|
||||
}
|
||||
}
|
||||
@ -473,7 +475,7 @@ static int32_t mz_zip_write_cd(void *handle)
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_write(zip->stream, zip->comment, comment_size) != comment_size)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_READ_ERROR;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
@ -1181,7 +1183,7 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_write(stream, filename, filename_length) != filename_length)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_WRITE_ERROR;
|
||||
|
||||
// Ensure that directories have a slash appended to them for compatibility
|
||||
if (err == MZ_OK && write_end_slash)
|
||||
@ -1278,7 +1280,7 @@ static int32_t mz_zip_entry_write_header(void *stream, uint8_t local, mz_zip_fil
|
||||
if ((err == MZ_OK) && (!local) && (file_info->comment != NULL))
|
||||
{
|
||||
if (mz_stream_write(stream, file_info->comment, file_info->comment_size) != file_info->comment_size)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return err;
|
||||
|
14
mz_zip_rw.c
14
mz_zip_rw.c
@ -90,7 +90,7 @@ int32_t mz_zip_reader_open(void *handle, void *stream)
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
mz_zip_reader_close(handle);
|
||||
return MZ_STREAM_ERROR;
|
||||
return err;
|
||||
}
|
||||
|
||||
mz_zip_reader_unzip_cd(reader);
|
||||
@ -504,7 +504,7 @@ int32_t mz_zip_reader_entry_sign_verify(void *handle)
|
||||
{
|
||||
signature = (uint8_t *)MZ_ALLOC(signature_size);
|
||||
if (mz_stream_read(file_extra_stream, signature, signature_size) != signature_size)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_READ_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_mem_delete(&file_extra_stream);
|
||||
@ -664,7 +664,7 @@ int32_t mz_zip_reader_entry_save_process(void *handle, void *stream, mz_stream_w
|
||||
// Write the data to the specified stream
|
||||
written = write_cb(stream, reader->buffer, read);
|
||||
if (written != read)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
}
|
||||
|
||||
return read;
|
||||
@ -1057,7 +1057,7 @@ static int32_t mz_zip_writer_open_int(void *handle, void *stream, int32_t mode)
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
mz_zip_writer_close(handle);
|
||||
return MZ_STREAM_ERROR;
|
||||
return err;
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
@ -1341,7 +1341,7 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_write(writer->file_extra_stream, sha256, sizeof(sha256)) != MZ_HASH_SHA256_SIZE)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_WRITE_ERROR;
|
||||
}
|
||||
|
||||
#ifndef MZ_ZIP_NO_SIGNING
|
||||
@ -1411,7 +1411,7 @@ int32_t mz_zip_writer_entry_sign(void *handle, uint8_t *message, int32_t message
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
if (mz_stream_write(writer->file_extra_stream, signature, signature_size) != signature_size)
|
||||
err = MZ_STREAM_ERROR;
|
||||
err = MZ_WRITE_ERROR;
|
||||
}
|
||||
|
||||
MZ_FREE(signature);
|
||||
@ -1448,7 +1448,7 @@ int32_t mz_zip_writer_add_process(void *handle, void *stream, mz_stream_read_cb
|
||||
|
||||
written = mz_zip_writer_entry_write(handle, writer->buffer, read);
|
||||
if (written != read)
|
||||
return MZ_STREAM_ERROR;
|
||||
return MZ_WRITE_ERROR;
|
||||
|
||||
return written;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user