mirror of
https://github.com/zlib-ng/minizip-ng
synced 2026-08-25 14:26:08 -04:00
Move stdio to the source files that use them.
Fixed limits redefinition for windows. Clean up headers.
This commit is contained in:
parent
6f3a0a6ad0
commit
e849627093
15 changed files with 77 additions and 74 deletions
|
|
@ -20,6 +20,8 @@
|
|||
#include "mz_zip.h"
|
||||
#include "mz_zip_rw.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct minizip_opt_s {
|
||||
|
|
|
|||
64
mz.h
64
mz.h
|
|
@ -145,30 +145,22 @@
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h> /* size_t and NULL */
|
||||
#include <time.h> /* time_t and time() */
|
||||
#include <string.h>
|
||||
#include <stdlib.h> /* size_t, NULL, malloc */
|
||||
#include <time.h> /* time_t, time() */
|
||||
#include <string.h> /* memset, strncpy, strlen */
|
||||
#include <limits.h>
|
||||
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 32767
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX 2147483647
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 65535U
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX 4294967295U
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
# define UINT64_MAX 18446744073709551615LL
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#else
|
||||
typedef signed char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_INTTYPES_H
|
||||
|
|
@ -190,17 +182,23 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_STDINT_H
|
||||
# include <stdint.h>
|
||||
#else
|
||||
typedef signed char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int64_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#ifndef INT16_MAX
|
||||
# define INT16_MAX 32767
|
||||
#endif
|
||||
#ifndef INT32_MAX
|
||||
# define INT32_MAX 2147483647
|
||||
#endif
|
||||
#ifndef INT64_MAX
|
||||
# define INT64_MAX 9223372036854775807LL
|
||||
#endif
|
||||
#ifndef UINT16_MAX
|
||||
# define UINT16_MAX 65535U
|
||||
#endif
|
||||
#ifndef UINT32_MAX
|
||||
# define UINT32_MAX 4294967295U
|
||||
#endif
|
||||
#ifndef UINT64_MAX
|
||||
# define UINT64_MAX 18446744073709551615LL
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
|
|||
|
|
@ -11,11 +11,6 @@
|
|||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
|
|
@ -25,6 +20,8 @@
|
|||
#include "mz_strm_zlib.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include <stdio.h> /* SEEK */
|
||||
|
||||
#include "mz_compat.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
@ -956,7 +953,7 @@ int ZEXPORT unzSeek64(unzFile file, int64_t offset, int origin)
|
|||
|
||||
err = mz_zip_get_stream(compat->handle, &stream);
|
||||
if (err == MZ_OK)
|
||||
err = mz_stream_seek(stream, compat->entry_pos + position, SEEK_SET);
|
||||
err = mz_stream_seek(stream, compat->entry_pos + position, MZ_SEEK_SET);
|
||||
if (err == MZ_OK)
|
||||
compat->total_out = position;
|
||||
return err;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(HAVE_ZLIB) && defined(MAX_MEM_LEVEL)
|
||||
#ifndef DEF_MEM_LEVEL
|
||||
# if MAX_MEM_LEVEL >= 8
|
||||
|
|
@ -232,7 +234,7 @@ typedef int (*unzIteratorFunction2)(unzFile file, unz_file_info64 *pfile_info, c
|
|||
uint16_t comment_size);
|
||||
|
||||
/***************************************************************************/
|
||||
/* Opening and close a zip file */
|
||||
/* Reading a zip file */
|
||||
|
||||
unzFile ZEXPORT unzOpen(const char *path);
|
||||
unzFile ZEXPORT unzOpen64(const void *path);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <CommonCrypto/CommonCryptor.h>
|
||||
#include <CommonCrypto/CommonDigest.h>
|
||||
|
|
@ -18,8 +20,6 @@
|
|||
#include <Security/Security.h>
|
||||
#include <Security/SecPolicy.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_crypt_rand(uint8_t *buf, int32_t size)
|
||||
|
|
|
|||
|
|
@ -13,14 +13,11 @@
|
|||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(HAVE_GETRANDOM)
|
||||
# include <sys/random.h>
|
||||
#endif
|
||||
#if defined(HAVE_LIBBSD)
|
||||
# include <sys/types.h>
|
||||
# ifndef __u_char_defined
|
||||
typedef unsigned char u_char;
|
||||
# endif
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@
|
|||
*/
|
||||
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/sha.h>
|
||||
|
|
@ -19,8 +21,6 @@
|
|||
#include <openssl/cms.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "mz.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_crypt_init(void)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_os.h"
|
||||
|
||||
#include <stdio.h> /* rename */
|
||||
#include <errno.h>
|
||||
#include <iconv.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -16,8 +16,6 @@
|
|||
|
||||
#include <compression.h>
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_libcomp_vtbl = {
|
||||
|
|
@ -384,13 +382,6 @@ void mz_stream_libcomp_delete(void **stream)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
/* Define z_crc_t in zlib 1.2.5 and less */
|
||||
#if (ZLIB_VERNUM < 0x1270)
|
||||
typedef unsigned long z_crc_t;
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_zlib_vtbl = {
|
||||
mz_stream_libcomp_open,
|
||||
mz_stream_libcomp_is_open,
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <stdio.h> /* fopen, fread.. */
|
||||
#include <errno.h>
|
||||
|
||||
/***************************************************************************/
|
||||
|
|
|
|||
|
|
@ -23,10 +23,6 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_crypt.h"
|
||||
#include "mz_strm.h"
|
||||
|
|
|
|||
|
|
@ -15,6 +15,12 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_strm_split.h"
|
||||
|
||||
#include <stdio.h> /* snprintf */
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_ZIP_MAGIC_DISKHEADER (0x08074b50)
|
||||
|
|
@ -58,10 +64,6 @@ typedef struct mz_stream_split_s {
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
# define mz_stream_split_print printf
|
||||
#else
|
||||
|
|
|
|||
3
mz_zip.c
3
mz_zip.c
|
|
@ -43,8 +43,9 @@
|
|||
#include "mz_zip.h"
|
||||
|
||||
#include <ctype.h> /* tolower */
|
||||
#include <stdio.h> /* snprintf */
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER < 1900
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
#include <stdio.h> /* printf */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
@ -36,6 +38,13 @@ int main(int argc, char **argv)
|
|||
int32_t read = 0;
|
||||
int32_t i = 0;
|
||||
|
||||
|
||||
if (argc < 1)
|
||||
{
|
||||
printf("Must specify an input file\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Running %"PRId32" inputs\n", argc - 1);
|
||||
|
||||
for (i = 1; (i < argc) && (err == MZ_OK); i++)
|
||||
|
|
@ -51,13 +60,13 @@ int main(int argc, char **argv)
|
|||
}
|
||||
else
|
||||
{
|
||||
mz_stream_os_seek(stream, 0, SEEK_END);
|
||||
mz_stream_os_seek(stream, 0, MZ_SEEK_END);
|
||||
file_size = mz_stream_os_tell(stream);
|
||||
if (file_size > INT32_MAX)
|
||||
printf("File size is too large (%lld)\n", file_size);
|
||||
printf("File size is too large (%"PRId64")\n", file_size);
|
||||
else
|
||||
buf_length = (int32_t)file_size;
|
||||
mz_stream_os_seek(stream, 0, SEEK_SET);
|
||||
mz_stream_os_seek(stream, 0, MZ_SEEK_SET);
|
||||
|
||||
if (buf_length > 0)
|
||||
buf = MZ_ALLOC(buf_length);
|
||||
|
|
|
|||
16
test/test.c
16
test/test.c
|
|
@ -29,6 +29,12 @@
|
|||
#endif
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include <stdio.h> /* printf, snprintf */
|
||||
|
||||
#if defined(_MSC_VER) && (_MSC_VER < 1900)
|
||||
# define snprintf _snprintf
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void test_path_resolve_int(char *path, char *expected_path)
|
||||
|
|
@ -70,7 +76,7 @@ void test_encrypt(char *method, mz_stream_create_cb crypt_create, char *password
|
|||
void *crypt_out_stream = NULL;
|
||||
char encrypt_path[120];
|
||||
char decrypt_path[120];
|
||||
|
||||
|
||||
snprintf(encrypt_path, sizeof(encrypt_path), "LICENSE.encrypt.%s", method);
|
||||
snprintf(decrypt_path, sizeof(decrypt_path), "LICENSE.decrypt.%s", method);
|
||||
|
||||
|
|
@ -425,7 +431,7 @@ int32_t test_stream_find_run(char *name, int32_t count, const uint8_t *find, int
|
|||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, SEEK_SET);
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, i + find_size, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
|
|
@ -446,7 +452,7 @@ int32_t test_stream_find_run(char *name, int32_t count, const uint8_t *find, int
|
|||
mz_stream_write_uint8(mem_stream, find[x]);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, SEEK_SET);
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, i + find_size, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
|
|
@ -469,7 +475,7 @@ int32_t test_stream_find_run(char *name, int32_t count, const uint8_t *find, int
|
|||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, SEEK_SET);
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, i + find_size + i, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
|
|
@ -493,7 +499,7 @@ int32_t test_stream_find_run(char *name, int32_t count, const uint8_t *find, int
|
|||
mz_stream_write_uint8(mem_stream, 0);
|
||||
|
||||
if (find_cb == mz_stream_find)
|
||||
mz_stream_seek(mem_stream, 0, SEEK_SET);
|
||||
mz_stream_seek(mem_stream, 0, MZ_SEEK_SET);
|
||||
|
||||
err = find_cb(mem_stream, (const void *)find, find_size, i + find_size + i + 1, &position);
|
||||
last_pos = mz_stream_tell(mem_stream);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue