mirror of
https://github.com/zlib-ng/minizip-ng
synced 2026-08-25 14:26:08 -04:00
Combine os level headers.
Moved os utility functions into util class.
This commit is contained in:
parent
73025eb9db
commit
21a3102db4
16 changed files with 738 additions and 575 deletions
|
|
@ -65,14 +65,13 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/minizip.pc.cmakein ${MINIZIP_PC} @ONL
|
|||
set(PROJECT_NAME libminizip)
|
||||
|
||||
set(MINIZIP_SRC
|
||||
mz_os.c
|
||||
mz_compat.c
|
||||
mz_strm.c
|
||||
mz_strm_buf.c
|
||||
mz_strm_crc32.c
|
||||
mz_strm_mem.c
|
||||
mz_strm_posix.c
|
||||
mz_strm_split.c
|
||||
mz_util.c
|
||||
mz_zip.c
|
||||
mz_zip_rw.c)
|
||||
|
||||
|
|
@ -84,8 +83,8 @@ set(MINIZIP_PUBLIC_HEADERS
|
|||
mz_strm_buf.h
|
||||
mz_strm_crc32.h
|
||||
mz_strm_mem.h
|
||||
mz_strm_posix.h
|
||||
mz_strm_split.h
|
||||
mz_strm_os.h
|
||||
mz_util.h
|
||||
mz_zip.h
|
||||
mz_zip_rw.h)
|
||||
|
||||
|
|
@ -102,8 +101,7 @@ endif()
|
|||
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
|
||||
if(WIN32)
|
||||
list(APPEND MINIZIP_SRC "mz_os_win32.c" "mz_strm_win32.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_os_win32.h" "mz_strm_win32.h")
|
||||
list(APPEND MINIZIP_SRC "mz_os_win32.c" "mz_strm_os_win32.c")
|
||||
|
||||
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
|
||||
endif()
|
||||
|
|
@ -119,8 +117,7 @@ endif()
|
|||
if(UNIX)
|
||||
add_compile_options(-O3)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_os_posix.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_os_posix.h")
|
||||
list(APPEND MINIZIP_SRC "mz_os_posix.c" "mz_strm_os_posix.c")
|
||||
|
||||
set(define_lfs_macros TRUE)
|
||||
|
||||
|
|
@ -179,8 +176,8 @@ endif()
|
|||
if(USE_AES)
|
||||
add_definitions(-DHAVE_AES)
|
||||
|
||||
list(APPEND MINIZIP_SRC "mz_strm_aes.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_aes.h")
|
||||
list(APPEND MINIZIP_SRC "mz_strm_wzaes.c")
|
||||
list(APPEND MINIZIP_PUBLIC_HEADERS "mz_strm_wzaes.h")
|
||||
|
||||
set(AES_SRC
|
||||
lib/aes/aescrypt.c
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_strm_buf.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_util.h"
|
||||
#include "mz_zip.h"
|
||||
#include "mz_zip_rw.h"
|
||||
|
||||
|
|
|
|||
1
mz.h
1
mz.h
|
|
@ -38,6 +38,7 @@ extern "C" {
|
|||
#define MZ_EXIST_ERROR (-107)
|
||||
#define MZ_PASSWORD_ERROR (-108)
|
||||
#define MZ_SUPPORT_ERROR (-109)
|
||||
#define MZ_HASH_ERROR (-110)
|
||||
|
||||
// MZ_OPEN
|
||||
#define MZ_OPEN_MODE_READ (0x01)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_strm_os.h"
|
||||
#include "mz_strm_zlib.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
|
|
|
|||
82
mz_os.h
82
mz_os.h
|
|
@ -20,16 +20,14 @@ extern "C" {
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_WIN32_API)
|
||||
#include "mz_os_posix.h"
|
||||
#include "mz_strm_posix.h"
|
||||
#else
|
||||
#include "mz_os_win32.h"
|
||||
#include "mz_strm_win32.h"
|
||||
#if defined(__APPLE__)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
|
||||
#elif defined(unix)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
|
||||
#elif defined(_WIN32)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef HAVE_LZMA
|
||||
#define MZ_VERSION_MADEBY_ZIP_VERSION (63)
|
||||
#elif HAVE_AES
|
||||
|
|
@ -45,29 +43,65 @@ extern "C" {
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
// Combines two paths
|
||||
#if defined(_WIN32)
|
||||
struct dirent {
|
||||
char d_name[256];
|
||||
};
|
||||
typedef void* DIR;
|
||||
#endif
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
|
||||
// Compare two paths with wildcard
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
|
||||
// Resolves path
|
||||
wchar_t *mz_os_unicode_string_create(const char *string);
|
||||
void mz_os_unicode_string_delete(wchar_t **string);
|
||||
|
||||
int32_t mz_path_remove_filename(char *path);
|
||||
// Remove the filename from a path
|
||||
int32_t mz_os_rename(const char *source_path, const char *target_path);
|
||||
int32_t mz_os_delete(const char *path);
|
||||
int32_t mz_os_file_exists(const char *path);
|
||||
int64_t mz_os_get_file_size(const char *path);
|
||||
int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes);
|
||||
int32_t mz_os_make_dir(const char *path);
|
||||
DIR* mz_os_open_dir(const char *path);
|
||||
struct
|
||||
dirent* mz_os_read_dir(DIR *dir);
|
||||
int32_t mz_os_close_dir(DIR *dir);
|
||||
int32_t mz_os_is_dir(const char *path);
|
||||
uint64_t mz_os_ms_time(void);
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename);
|
||||
// Get the filename from a path
|
||||
int32_t mz_os_rand(uint8_t *buf, int32_t size);
|
||||
|
||||
int32_t mz_dir_make(const char *path);
|
||||
// Creates a directory recursively
|
||||
void mz_os_sha_reset(void *handle);
|
||||
int32_t mz_os_sha_begin(void *handle);
|
||||
int32_t mz_os_sha_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_os_sha_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
void mz_os_sha_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_os_sha_create(void **handle);
|
||||
void mz_os_sha_delete(void **handle);
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
|
||||
// Gets the crc32 hash of a file
|
||||
void mz_os_aes_reset(void *handle);
|
||||
int32_t mz_os_aes_encrypt(void *handle, uint8_t *buf, int32_t size, int32_t final);
|
||||
int32_t mz_os_aes_decrypt(void *handle, uint8_t *buf, int32_t size, int32_t final);
|
||||
int32_t mz_os_aes_set_key(void *handle, const void *key, int32_t key_length);
|
||||
void mz_os_aes_set_mode(void *handle, int32_t mode);
|
||||
void mz_os_aes_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_os_aes_create(void **handle);
|
||||
void mz_os_aes_delete(void **handle);
|
||||
|
||||
int32_t mz_encoding_cp437_to_utf8(const char *source, char *target, int32_t max_target);
|
||||
// Converts ibm cp437 encoded string to utf8
|
||||
void mz_os_hmac_reset(void *handle);
|
||||
int32_t mz_os_hmac_begin(void *handle);
|
||||
int32_t mz_os_hmac_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_os_hmac_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
int32_t mz_os_hmac_set_key(void *handle, const void *key, int32_t key_length);
|
||||
void mz_os_hmac_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_os_hmac_create(void **handle);
|
||||
void mz_os_hmac_delete(void **handle);
|
||||
|
||||
int32_t mz_os_sign(uint8_t *message, int32_t message_size, const char *cert_path, const char *cert_pwd,
|
||||
const char *timestamp_url, uint8_t **signature, int32_t *signature_size);
|
||||
int32_t mz_os_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
/* mz_os_posix.h -- System functions for posix
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_OS_POSIX_H
|
||||
#define MZ_OS_POSIX_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_OSX_DARWIN)
|
||||
#elif defined(unix)
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_UNIX)
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_posix_rand(uint8_t *buf, int32_t size);
|
||||
int32_t mz_posix_rename(const char *source_path, const char *target_path);
|
||||
int32_t mz_posix_delete(const char *path);
|
||||
int32_t mz_posix_file_exists(const char *path);
|
||||
int64_t mz_posix_get_file_size(const char *path);
|
||||
int32_t mz_posix_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
int32_t mz_posix_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
int32_t mz_posix_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
int32_t mz_posix_set_file_attribs(const char *path, uint32_t attributes);
|
||||
int32_t mz_posix_make_dir(const char *path);
|
||||
DIR* mz_posix_open_dir(const char *path);
|
||||
struct
|
||||
dirent* mz_posix_read_dir(DIR *dir);
|
||||
int32_t mz_posix_close_dir(DIR *dir);
|
||||
int32_t mz_posix_is_dir(const char *path);
|
||||
uint64_t mz_posix_ms_time(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define mz_os_rand mz_posix_rand
|
||||
#define mz_os_rename mz_posix_rename
|
||||
#define mz_os_delete mz_posix_delete
|
||||
#define mz_os_file_exists mz_posix_file_exists
|
||||
#define mz_os_get_file_size mz_posix_get_file_size
|
||||
#define mz_os_get_file_date mz_posix_get_file_date
|
||||
#define mz_os_set_file_date mz_posix_set_file_date
|
||||
#define mz_os_get_file_attribs mz_posix_get_file_attribs
|
||||
#define mz_os_set_file_attribs mz_posix_set_file_attribs
|
||||
#define mz_os_make_dir mz_posix_make_dir
|
||||
#define mz_os_open_dir mz_posix_open_dir
|
||||
#define mz_os_read_dir mz_posix_read_dir
|
||||
#define mz_os_close_dir mz_posix_close_dir
|
||||
#define mz_os_is_dir mz_posix_is_dir
|
||||
#define mz_os_ms_time mz_posix_ms_time
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
253
mz_os_win32.c
253
mz_os_win32.c
|
|
@ -25,7 +25,8 @@
|
|||
#include "mz.h"
|
||||
|
||||
#include "mz_os.h"
|
||||
#include "mz_os_win32.h"
|
||||
#include "mz_strm_os.h"
|
||||
#include "mz_util.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
|
@ -46,7 +47,7 @@ typedef struct DIR_int_s {
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
wchar_t *mz_win32_unicode_string_create(const char *string)
|
||||
wchar_t *mz_os_unicode_string_create(const char *string)
|
||||
{
|
||||
wchar_t *string_wide = NULL;
|
||||
uint32_t string_wide_size = 0;
|
||||
|
|
@ -60,7 +61,7 @@ wchar_t *mz_win32_unicode_string_create(const char *string)
|
|||
return string_wide;
|
||||
}
|
||||
|
||||
void mz_win32_unicode_string_delete(wchar_t **string)
|
||||
void mz_os_unicode_string_delete(wchar_t **string)
|
||||
{
|
||||
if (string != NULL)
|
||||
{
|
||||
|
|
@ -71,18 +72,18 @@ void mz_win32_unicode_string_delete(wchar_t **string)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_win32_rename(const char *source_path, const char *target_path)
|
||||
int32_t mz_os_rename(const char *source_path, const char *target_path)
|
||||
{
|
||||
wchar_t *source_path_wide = NULL;
|
||||
wchar_t *target_path_wide = NULL;
|
||||
int32_t result = 0;
|
||||
|
||||
|
||||
source_path_wide = mz_win32_unicode_string_create(source_path);
|
||||
target_path_wide = mz_win32_unicode_string_create(target_path);
|
||||
source_path_wide = mz_os_unicode_string_create(source_path);
|
||||
target_path_wide = mz_os_unicode_string_create(target_path);
|
||||
result = MoveFileW(source_path_wide, target_path_wide);
|
||||
mz_win32_unicode_string_delete(&source_path_wide);
|
||||
mz_win32_unicode_string_delete(&target_path_wide);
|
||||
mz_os_unicode_string_delete(&source_path_wide);
|
||||
mz_os_unicode_string_delete(&target_path_wide);
|
||||
|
||||
if (result == 0)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
|
@ -90,15 +91,15 @@ int32_t mz_win32_rename(const char *source_path, const char *target_path)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_delete(const char *path)
|
||||
int32_t mz_os_delete(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t result = 0;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
result = DeleteFileW(path_wide);
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (result == 0)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
|
@ -106,15 +107,15 @@ int32_t mz_win32_delete(const char *path)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_file_exists(const char *path)
|
||||
int32_t mz_os_file_exists(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
DWORD attribs = 0;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
attribs = GetFileAttributesW(path_wide);
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (attribs == 0xFFFFFFFF)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
|
@ -122,20 +123,20 @@ int32_t mz_win32_file_exists(const char *path)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int64_t mz_win32_get_file_size(const char *path)
|
||||
int64_t mz_os_get_file_size(const char *path)
|
||||
{
|
||||
HANDLE handle = NULL;
|
||||
LARGE_INTEGER large_size;
|
||||
wchar_t *path_wide = NULL;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
#ifdef MZ_WINRT_API
|
||||
handle = CreateFile2W(path_wide, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#else
|
||||
handle = CreateFileW(path_wide, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#endif
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
large_size.QuadPart = 0;
|
||||
|
||||
|
|
@ -148,7 +149,7 @@ int64_t mz_win32_get_file_size(const char *path)
|
|||
return large_size.QuadPart;
|
||||
}
|
||||
|
||||
static void mz_win32_file_to_unix_time(FILETIME file_time, time_t *unix_time)
|
||||
static void mz_os_file_to_unix_time(FILETIME file_time, time_t *unix_time)
|
||||
{
|
||||
uint64_t quad_file_time = 0;
|
||||
quad_file_time = file_time.dwLowDateTime;
|
||||
|
|
@ -156,7 +157,7 @@ static void mz_win32_file_to_unix_time(FILETIME file_time, time_t *unix_time)
|
|||
*unix_time = (time_t)((quad_file_time - 116444736000000000LL) / 10000000);
|
||||
}
|
||||
|
||||
static void mz_win32_unix_to_file_time(time_t unix_time, FILETIME *file_time)
|
||||
static void mz_os_unix_to_file_time(time_t unix_time, FILETIME *file_time)
|
||||
{
|
||||
uint64_t quad_file_time = 0;
|
||||
quad_file_time = ((uint64_t)unix_time * 10000000) + 116444736000000000LL;
|
||||
|
|
@ -164,25 +165,25 @@ static void mz_win32_unix_to_file_time(time_t unix_time, FILETIME *file_time)
|
|||
file_time->dwLowDateTime = (uint32_t)(quad_file_time);
|
||||
}
|
||||
|
||||
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date)
|
||||
int32_t mz_os_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date)
|
||||
{
|
||||
WIN32_FIND_DATAW ff32;
|
||||
HANDLE handle = NULL;
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_INTERNAL_ERROR;
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
handle = FindFirstFileW(path_wide, &ff32);
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
if (handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
if (modified_date != NULL)
|
||||
mz_win32_file_to_unix_time(ff32.ftLastWriteTime, modified_date);
|
||||
mz_os_file_to_unix_time(ff32.ftLastWriteTime, modified_date);
|
||||
if (accessed_date != NULL)
|
||||
mz_win32_file_to_unix_time(ff32.ftLastAccessTime, accessed_date);
|
||||
mz_os_file_to_unix_time(ff32.ftLastAccessTime, accessed_date);
|
||||
if (creation_date != NULL)
|
||||
mz_win32_file_to_unix_time(ff32.ftCreationTime, creation_date);
|
||||
mz_os_file_to_unix_time(ff32.ftCreationTime, creation_date);
|
||||
|
||||
FindClose(handle);
|
||||
err = MZ_OK;
|
||||
|
|
@ -191,7 +192,7 @@ int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date)
|
||||
int32_t mz_os_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date)
|
||||
{
|
||||
HANDLE handle = NULL;
|
||||
FILETIME ftm_creation, ftm_accessed, ftm_modified;
|
||||
|
|
@ -199,24 +200,24 @@ int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t ac
|
|||
int32_t err = MZ_OK;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
#ifdef MZ_WINRT_API
|
||||
handle = CreateFile2W(path_wide, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
#else
|
||||
handle = CreateFileW(path_wide, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
|
||||
#endif
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (handle != INVALID_HANDLE_VALUE)
|
||||
{
|
||||
GetFileTime(handle, &ftm_creation, &ftm_accessed, &ftm_modified);
|
||||
|
||||
if (modified_date != 0)
|
||||
mz_win32_unix_to_file_time(modified_date, &ftm_modified);
|
||||
mz_os_unix_to_file_time(modified_date, &ftm_modified);
|
||||
if (accessed_date != 0)
|
||||
mz_win32_unix_to_file_time(accessed_date, &ftm_accessed);
|
||||
mz_os_unix_to_file_time(accessed_date, &ftm_accessed);
|
||||
if (creation_date != 0)
|
||||
mz_win32_unix_to_file_time(creation_date, &ftm_creation);
|
||||
mz_os_unix_to_file_time(creation_date, &ftm_creation);
|
||||
|
||||
if (SetFileTime(handle, &ftm_creation, &ftm_accessed, &ftm_modified) == 0)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
|
|
@ -227,12 +228,12 @@ int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t ac
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes)
|
||||
int32_t mz_os_get_file_attribs(const char *path, uint32_t *attributes)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
*attributes = GetFileAttributesW(path_wide);
|
||||
MZ_FREE(path_wide);
|
||||
|
||||
|
|
@ -242,12 +243,12 @@ int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes)
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes)
|
||||
int32_t mz_os_set_file_attribs(const char *path, uint32_t attributes)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
if (SetFileAttributesW(path_wide, attributes) == 0)
|
||||
err = MZ_INTERNAL_ERROR;
|
||||
MZ_FREE(path_wide);
|
||||
|
|
@ -255,15 +256,15 @@ int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes)
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_make_dir(const char *path)
|
||||
int32_t mz_os_make_dir(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
int32_t err = 0;
|
||||
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
err = _wmkdir(path_wide);
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (err != 0 && errno != EEXIST)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
|
@ -271,7 +272,7 @@ int32_t mz_win32_make_dir(const char *path)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
DIR *mz_win32_open_dir(const char *path)
|
||||
DIR *mz_os_open_dir(const char *path)
|
||||
{
|
||||
WIN32_FIND_DATAW find_data;
|
||||
DIR_int *dir_int = NULL;
|
||||
|
|
@ -284,9 +285,9 @@ DIR *mz_win32_open_dir(const char *path)
|
|||
mz_path_combine(fixed_path, path, sizeof(fixed_path));
|
||||
mz_path_combine(fixed_path, "*", sizeof(fixed_path));
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(fixed_path);
|
||||
path_wide = mz_os_unicode_string_create(fixed_path);
|
||||
handle = FindFirstFileW(path_wide, &find_data);
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (handle == INVALID_HANDLE_VALUE)
|
||||
return NULL;
|
||||
|
|
@ -300,7 +301,7 @@ DIR *mz_win32_open_dir(const char *path)
|
|||
return (DIR *)dir_int;
|
||||
}
|
||||
|
||||
struct dirent* mz_win32_read_dir(DIR *dir)
|
||||
struct dirent* mz_os_read_dir(DIR *dir)
|
||||
{
|
||||
DIR_int *dir_int;
|
||||
|
||||
|
|
@ -325,7 +326,7 @@ struct dirent* mz_win32_read_dir(DIR *dir)
|
|||
return &dir_int->entry;
|
||||
}
|
||||
|
||||
int32_t mz_win32_close_dir(DIR *dir)
|
||||
int32_t mz_os_close_dir(DIR *dir)
|
||||
{
|
||||
DIR_int *dir_int;
|
||||
|
||||
|
|
@ -339,14 +340,14 @@ int32_t mz_win32_close_dir(DIR *dir)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_is_dir(const char *path)
|
||||
int32_t mz_os_is_dir(const char *path)
|
||||
{
|
||||
wchar_t *path_wide = NULL;
|
||||
uint32_t attribs = 0;
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
attribs = GetFileAttributesW(path_wide);
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (attribs != 0xFFFFFFFF)
|
||||
{
|
||||
|
|
@ -357,7 +358,7 @@ int32_t mz_win32_is_dir(const char *path)
|
|||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
uint64_t mz_win32_ms_time(void)
|
||||
uint64_t mz_os_ms_time(void)
|
||||
{
|
||||
SYSTEMTIME system_time;
|
||||
FILETIME file_time;
|
||||
|
|
@ -375,7 +376,7 @@ uint64_t mz_win32_ms_time(void)
|
|||
/***************************************************************************/
|
||||
#if !defined(MZ_ZIP_NO_ENCRYPTION)
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION)
|
||||
int32_t mz_win32_rand(uint8_t *buf, int32_t size)
|
||||
int32_t mz_os_rand(uint8_t *buf, int32_t size)
|
||||
{
|
||||
HCRYPTPROV provider;
|
||||
unsigned __int64 pentium_tsc[1];
|
||||
|
|
@ -405,18 +406,18 @@ int32_t mz_win32_rand(uint8_t *buf, int32_t size)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_win32_sha_s {
|
||||
typedef struct mz_os_sha_s {
|
||||
HCRYPTPROV provider;
|
||||
HCRYPTHASH hash;
|
||||
int32_t error;
|
||||
uint16_t algorithm;
|
||||
} mz_win32_sha;
|
||||
} mz_os_sha;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
void mz_win32_sha_reset(void *handle)
|
||||
void mz_os_sha_reset(void *handle)
|
||||
{
|
||||
mz_win32_sha *sha = (mz_win32_sha *)handle;
|
||||
mz_os_sha *sha = (mz_os_sha *)handle;
|
||||
if (sha->hash)
|
||||
CryptDestroyHash(sha->hash);
|
||||
sha->hash = 0;
|
||||
|
|
@ -426,9 +427,9 @@ void mz_win32_sha_reset(void *handle)
|
|||
sha->error = 0;
|
||||
}
|
||||
|
||||
int32_t mz_win32_sha_begin(void *handle)
|
||||
int32_t mz_os_sha_begin(void *handle)
|
||||
{
|
||||
mz_win32_sha *sha = (mz_win32_sha *)handle;
|
||||
mz_os_sha *sha = (mz_os_sha *)handle;
|
||||
ALG_ID alg_id = 0;
|
||||
int32_t result = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
|
@ -462,9 +463,9 @@ int32_t mz_win32_sha_begin(void *handle)
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_sha_update(void *handle, const void *buf, int32_t size)
|
||||
int32_t mz_os_sha_update(void *handle, const void *buf, int32_t size)
|
||||
{
|
||||
mz_win32_sha *sha = (mz_win32_sha *)handle;
|
||||
mz_os_sha *sha = (mz_os_sha *)handle;
|
||||
int32_t result = 0;
|
||||
|
||||
if (sha == NULL || buf == NULL)
|
||||
|
|
@ -478,9 +479,9 @@ int32_t mz_win32_sha_update(void *handle, const void *buf, int32_t size)
|
|||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_win32_sha_end(void *handle, uint8_t *digest, int32_t digest_size)
|
||||
int32_t mz_os_sha_end(void *handle, uint8_t *digest, int32_t digest_size)
|
||||
{
|
||||
mz_win32_sha *sha = (mz_win32_sha *)handle;
|
||||
mz_os_sha *sha = (mz_os_sha *)handle;
|
||||
int32_t result = 0;
|
||||
int32_t expected_size = 0;
|
||||
|
||||
|
|
@ -500,20 +501,20 @@ int32_t mz_win32_sha_end(void *handle, uint8_t *digest, int32_t digest_size)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
void mz_win32_sha_set_algorithm(void *handle, uint16_t algorithm)
|
||||
void mz_os_sha_set_algorithm(void *handle, uint16_t algorithm)
|
||||
{
|
||||
mz_win32_sha *sha = (mz_win32_sha *)handle;
|
||||
mz_os_sha *sha = (mz_os_sha *)handle;
|
||||
sha->algorithm = algorithm;
|
||||
}
|
||||
|
||||
void *mz_win32_sha_create(void **handle)
|
||||
void *mz_os_sha_create(void **handle)
|
||||
{
|
||||
mz_win32_sha *sha = NULL;
|
||||
mz_os_sha *sha = NULL;
|
||||
|
||||
sha = (mz_win32_sha *)MZ_ALLOC(sizeof(mz_win32_sha));
|
||||
sha = (mz_os_sha *)MZ_ALLOC(sizeof(mz_os_sha));
|
||||
if (sha != NULL)
|
||||
{
|
||||
memset(sha, 0, sizeof(mz_win32_sha));
|
||||
memset(sha, 0, sizeof(mz_os_sha));
|
||||
sha->algorithm = MZ_HASH_SHA256;
|
||||
}
|
||||
if (handle != NULL)
|
||||
|
|
@ -522,15 +523,15 @@ void *mz_win32_sha_create(void **handle)
|
|||
return sha;
|
||||
}
|
||||
|
||||
void mz_win32_sha_delete(void **handle)
|
||||
void mz_os_sha_delete(void **handle)
|
||||
{
|
||||
mz_win32_sha *sha = NULL;
|
||||
mz_os_sha *sha = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
sha = (mz_win32_sha *)*handle;
|
||||
sha = (mz_os_sha *)*handle;
|
||||
if (sha != NULL)
|
||||
{
|
||||
mz_win32_sha_reset(*handle);
|
||||
mz_os_sha_reset(*handle);
|
||||
MZ_FREE(sha);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
|
@ -538,19 +539,19 @@ void mz_win32_sha_delete(void **handle)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_win32_aes_s {
|
||||
typedef struct mz_os_aes_s {
|
||||
HCRYPTPROV provider;
|
||||
HCRYPTKEY key;
|
||||
int32_t mode;
|
||||
int32_t error;
|
||||
uint16_t algorithm;
|
||||
} mz_win32_aes;
|
||||
} mz_os_aes;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_win32_aes_free(void *handle)
|
||||
static void mz_os_aes_free(void *handle)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
if (aes->key)
|
||||
CryptDestroyKey(aes->key);
|
||||
aes->key = 0;
|
||||
|
|
@ -559,15 +560,15 @@ static void mz_win32_aes_free(void *handle)
|
|||
aes->provider = 0;
|
||||
}
|
||||
|
||||
void mz_win32_aes_reset(void *handle)
|
||||
void mz_os_aes_reset(void *handle)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_win32_aes_free(handle);
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
mz_os_aes_free(handle);
|
||||
}
|
||||
|
||||
int32_t mz_win32_aes_encrypt(void *handle, uint8_t *buf, int32_t size, int32_t final)
|
||||
int32_t mz_os_aes_encrypt(void *handle, uint8_t *buf, int32_t size, int32_t final)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
int32_t result = 0;
|
||||
int32_t buf_len = size;
|
||||
|
||||
|
|
@ -584,9 +585,9 @@ int32_t mz_win32_aes_encrypt(void *handle, uint8_t *buf, int32_t size, int32_t f
|
|||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_win32_aes_decrypt(void *handle, uint8_t *buf, int32_t size, int32_t final)
|
||||
int32_t mz_os_aes_decrypt(void *handle, uint8_t *buf, int32_t size, int32_t final)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
int32_t result = 0;
|
||||
if (aes == NULL || buf == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
|
@ -599,9 +600,9 @@ int32_t mz_win32_aes_decrypt(void *handle, uint8_t *buf, int32_t size, int32_t f
|
|||
return size;
|
||||
}
|
||||
|
||||
int32_t mz_win32_aes_set_key(void *handle, const void *key, int32_t key_length)
|
||||
int32_t mz_os_aes_set_key(void *handle, const void *key, int32_t key_length)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
HCRYPTHASH hash = 0;
|
||||
ALG_ID alg_id = 0;
|
||||
ALG_ID hash_alg_id = 0;
|
||||
|
|
@ -612,7 +613,7 @@ int32_t mz_win32_aes_set_key(void *handle, const void *key, int32_t key_length)
|
|||
if (aes == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_win32_aes_reset(handle);
|
||||
mz_os_aes_reset(handle);
|
||||
|
||||
if (aes->mode == MZ_AES_ENCRYPTION_MODE_128)
|
||||
alg_id = CALG_AES_128;
|
||||
|
|
@ -665,27 +666,27 @@ int32_t mz_win32_aes_set_key(void *handle, const void *key, int32_t key_length)
|
|||
return err;
|
||||
}
|
||||
|
||||
void mz_win32_aes_set_mode(void *handle, int32_t mode)
|
||||
void mz_os_aes_set_mode(void *handle, int32_t mode)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
aes->mode = mode;
|
||||
}
|
||||
|
||||
void mz_win32_aes_set_algorithm(void *handle, uint16_t algorithm)
|
||||
void mz_os_aes_set_algorithm(void *handle, uint16_t algorithm)
|
||||
{
|
||||
mz_win32_aes *aes = (mz_win32_aes *)handle;
|
||||
mz_os_aes *aes = (mz_os_aes *)handle;
|
||||
aes->algorithm = algorithm;
|
||||
}
|
||||
|
||||
void *mz_win32_aes_create(void **handle)
|
||||
void *mz_os_aes_create(void **handle)
|
||||
{
|
||||
mz_win32_aes *aes = NULL;
|
||||
mz_os_aes *aes = NULL;
|
||||
|
||||
aes = (mz_win32_aes *)MZ_ALLOC(sizeof(mz_win32_aes));
|
||||
aes = (mz_os_aes *)MZ_ALLOC(sizeof(mz_os_aes));
|
||||
if (aes != NULL)
|
||||
{
|
||||
aes->algorithm = MZ_HASH_SHA256;
|
||||
memset(aes, 0, sizeof(mz_win32_aes));
|
||||
memset(aes, 0, sizeof(mz_os_aes));
|
||||
}
|
||||
if (handle != NULL)
|
||||
*handle = aes;
|
||||
|
|
@ -693,15 +694,15 @@ void *mz_win32_aes_create(void **handle)
|
|||
return aes;
|
||||
}
|
||||
|
||||
void mz_win32_aes_delete(void **handle)
|
||||
void mz_os_aes_delete(void **handle)
|
||||
{
|
||||
mz_win32_aes *aes = NULL;
|
||||
mz_os_aes *aes = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
aes = (mz_win32_aes *)*handle;
|
||||
aes = (mz_os_aes *)*handle;
|
||||
if (aes != NULL)
|
||||
{
|
||||
mz_win32_aes_free(*handle);
|
||||
mz_os_aes_free(*handle);
|
||||
MZ_FREE(aes);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
|
@ -709,7 +710,7 @@ void mz_win32_aes_delete(void **handle)
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
typedef struct mz_win32_hmac_s {
|
||||
typedef struct mz_os_hmac_s {
|
||||
HCRYPTPROV provider;
|
||||
HCRYPTHASH hash;
|
||||
HCRYPTKEY key;
|
||||
|
|
@ -717,13 +718,13 @@ typedef struct mz_win32_hmac_s {
|
|||
int32_t mode;
|
||||
int32_t error;
|
||||
uint16_t algorithm;
|
||||
} mz_win32_hmac;
|
||||
} mz_os_hmac;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static void mz_win32_hmac_free(void *handle)
|
||||
static void mz_os_hmac_free(void *handle)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
if (hmac->key)
|
||||
CryptDestroyKey(hmac->key);
|
||||
hmac->key = 0;
|
||||
|
|
@ -736,15 +737,15 @@ static void mz_win32_hmac_free(void *handle)
|
|||
memset(&hmac->info, 0, sizeof(hmac->info));
|
||||
}
|
||||
|
||||
void mz_win32_hmac_reset(void *handle)
|
||||
void mz_os_hmac_reset(void *handle)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_win32_hmac_free(handle);
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
mz_os_hmac_free(handle);
|
||||
}
|
||||
|
||||
int32_t mz_win32_hmac_begin(void *handle)
|
||||
int32_t mz_os_hmac_begin(void *handle)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
int32_t result = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
||||
|
|
@ -768,9 +769,9 @@ int32_t mz_win32_hmac_begin(void *handle)
|
|||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_win32_hmac_update(void *handle, const void *buf, int32_t size)
|
||||
int32_t mz_os_hmac_update(void *handle, const void *buf, int32_t size)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
int32_t result = 0;
|
||||
|
||||
if (hmac == NULL || buf == NULL || hmac->hash == 0)
|
||||
|
|
@ -785,9 +786,9 @@ int32_t mz_win32_hmac_update(void *handle, const void *buf, int32_t size)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_hmac_end(void *handle, uint8_t *digest, int32_t digest_size)
|
||||
int32_t mz_os_hmac_end(void *handle, uint8_t *digest, int32_t digest_size)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
int32_t result = 0;
|
||||
int32_t expected_size = 0;
|
||||
int32_t err = MZ_OK;
|
||||
|
|
@ -808,9 +809,9 @@ int32_t mz_win32_hmac_end(void *handle, uint8_t *digest, int32_t digest_size)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_win32_hmac_set_key(void *handle, const void *key, int32_t key_length)
|
||||
int32_t mz_os_hmac_set_key(void *handle, const void *key, int32_t key_length)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
HCRYPTHASH hash = 0;
|
||||
ALG_ID alg_id = 0;
|
||||
typedef struct key_blob_header_s {
|
||||
|
|
@ -827,7 +828,7 @@ int32_t mz_win32_hmac_set_key(void *handle, const void *key, int32_t key_length)
|
|||
if (hmac == NULL || key == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
mz_win32_hmac_reset(handle);
|
||||
mz_os_hmac_reset(handle);
|
||||
|
||||
if (hmac->algorithm == MZ_HASH_SHA1)
|
||||
alg_id = CALG_SHA1;
|
||||
|
|
@ -865,25 +866,25 @@ int32_t mz_win32_hmac_set_key(void *handle, const void *key, int32_t key_length)
|
|||
MZ_FREE(key_blob);
|
||||
|
||||
if (err != MZ_OK)
|
||||
mz_win32_hmac_free(handle);
|
||||
mz_os_hmac_free(handle);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void mz_win32_hmac_set_algorithm(void *handle, uint16_t algorithm)
|
||||
void mz_os_hmac_set_algorithm(void *handle, uint16_t algorithm)
|
||||
{
|
||||
mz_win32_hmac *hmac = (mz_win32_hmac *)handle;
|
||||
mz_os_hmac *hmac = (mz_os_hmac *)handle;
|
||||
hmac->algorithm = algorithm;
|
||||
}
|
||||
|
||||
void *mz_win32_hmac_create(void **handle)
|
||||
void *mz_os_hmac_create(void **handle)
|
||||
{
|
||||
mz_win32_hmac *hmac = NULL;
|
||||
mz_os_hmac *hmac = NULL;
|
||||
|
||||
hmac = (mz_win32_hmac *)MZ_ALLOC(sizeof(mz_win32_hmac));
|
||||
hmac = (mz_os_hmac *)MZ_ALLOC(sizeof(mz_os_hmac));
|
||||
if (hmac != NULL)
|
||||
{
|
||||
memset(hmac, 0, sizeof(mz_win32_hmac));
|
||||
memset(hmac, 0, sizeof(mz_os_hmac));
|
||||
hmac->algorithm = MZ_HASH_SHA256;
|
||||
}
|
||||
if (handle != NULL)
|
||||
|
|
@ -892,15 +893,15 @@ void *mz_win32_hmac_create(void **handle)
|
|||
return hmac;
|
||||
}
|
||||
|
||||
void mz_win32_hmac_delete(void **handle)
|
||||
void mz_os_hmac_delete(void **handle)
|
||||
{
|
||||
mz_win32_hmac *hmac = NULL;
|
||||
mz_os_hmac *hmac = NULL;
|
||||
if (handle == NULL)
|
||||
return;
|
||||
hmac = (mz_win32_hmac *)*handle;
|
||||
hmac = (mz_os_hmac *)*handle;
|
||||
if (hmac != NULL)
|
||||
{
|
||||
mz_win32_hmac_free(*handle);
|
||||
mz_os_hmac_free(*handle);
|
||||
MZ_FREE(hmac);
|
||||
}
|
||||
*handle = NULL;
|
||||
|
|
@ -909,7 +910,7 @@ void mz_win32_hmac_delete(void **handle)
|
|||
/***************************************************************************/
|
||||
|
||||
#if !defined(MZ_ZIP_NO_COMPRESSION)
|
||||
int32_t mz_win32_sign(uint8_t *message, int32_t message_size, const char *cert_path, const char *cert_pwd,
|
||||
int32_t mz_os_sign(uint8_t *message, int32_t message_size, const char *cert_path, const char *cert_pwd,
|
||||
const char *timestamp_url, uint8_t **signature, int32_t *signature_size)
|
||||
{
|
||||
CRYPT_SIGN_MESSAGE_PARA sign_params;
|
||||
|
|
@ -955,9 +956,9 @@ int32_t mz_win32_sign(uint8_t *message, int32_t message_size, const char *cert_p
|
|||
|
||||
if ((err == MZ_OK) && (cert_pwd != NULL))
|
||||
{
|
||||
password_wide = mz_win32_unicode_string_create(cert_pwd);
|
||||
password_wide = mz_os_unicode_string_create(cert_pwd);
|
||||
cert_store = PFXImportCertStore(&cert_data_blob, password_wide, 0);
|
||||
mz_win32_unicode_string_delete(&password_wide);
|
||||
mz_os_unicode_string_delete(&password_wide);
|
||||
}
|
||||
|
||||
if (cert_store == NULL)
|
||||
|
|
@ -991,14 +992,14 @@ int32_t mz_win32_sign(uint8_t *message, int32_t message_size, const char *cert_p
|
|||
messages_sizes[0] = message_size;
|
||||
|
||||
if (timestamp_url != NULL)
|
||||
timestamp_url_wide = mz_win32_unicode_string_create(timestamp_url);
|
||||
timestamp_url_wide = mz_os_unicode_string_create(timestamp_url);
|
||||
if (timestamp_url_wide != NULL)
|
||||
{
|
||||
result = CryptRetrieveTimeStamp(timestamp_url_wide,
|
||||
TIMESTAMP_NO_AUTH_RETRIEVAL | TIMESTAMP_VERIFY_CONTEXT_SIGNATURE, 0, szOID_NIST_sha256,
|
||||
NULL, message, message_size, &ts_context, NULL, NULL);
|
||||
|
||||
mz_win32_unicode_string_delete(×tamp_url_wide);
|
||||
mz_os_unicode_string_delete(×tamp_url_wide);
|
||||
|
||||
if ((result) && (ts_context != NULL))
|
||||
{
|
||||
|
|
@ -1041,7 +1042,7 @@ int32_t mz_win32_sign(uint8_t *message, int32_t message_size, const char *cert_p
|
|||
}
|
||||
#endif
|
||||
|
||||
int32_t mz_win32_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size)
|
||||
int32_t mz_os_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size)
|
||||
{
|
||||
CRYPT_VERIFY_MESSAGE_PARA verify_params;
|
||||
CRYPT_TIMESTAMP_CONTEXT *crypt_context = NULL;
|
||||
|
|
|
|||
129
mz_os_win32.h
129
mz_os_win32.h
|
|
@ -1,129 +0,0 @@
|
|||
/* mz_os_win32.h -- System functions for Windows
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_OS_WIN32_H
|
||||
#define MZ_OS_WIN32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define MZ_VERSION_MADEBY_HOST_SYSTEM (MZ_HOST_SYSTEM_WINDOWS_NTFS)
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
struct dirent {
|
||||
char d_name[256];
|
||||
};
|
||||
typedef void* DIR;
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
wchar_t *mz_win32_unicode_string_create(const char *string);
|
||||
void mz_win32_unicode_string_delete(wchar_t **string);
|
||||
|
||||
int32_t mz_win32_rename(const char *source_path, const char *target_path);
|
||||
int32_t mz_win32_delete(const char *path);
|
||||
int32_t mz_win32_file_exists(const char *path);
|
||||
int64_t mz_win32_get_file_size(const char *path);
|
||||
int32_t mz_win32_get_file_date(const char *path, time_t *modified_date, time_t *accessed_date, time_t *creation_date);
|
||||
int32_t mz_win32_set_file_date(const char *path, time_t modified_date, time_t accessed_date, time_t creation_date);
|
||||
int32_t mz_win32_get_file_attribs(const char *path, uint32_t *attributes);
|
||||
int32_t mz_win32_set_file_attribs(const char *path, uint32_t attributes);
|
||||
int32_t mz_win32_make_dir(const char *path);
|
||||
DIR* mz_win32_open_dir(const char *path);
|
||||
struct
|
||||
dirent* mz_win32_read_dir(DIR *dir);
|
||||
int32_t mz_win32_close_dir(DIR *dir);
|
||||
int32_t mz_win32_is_dir(const char *path);
|
||||
uint64_t mz_win32_ms_time(void);
|
||||
|
||||
int32_t mz_win32_rand(uint8_t *buf, int32_t size);
|
||||
|
||||
void mz_win32_sha_reset(void *handle);
|
||||
int32_t mz_win32_sha_begin(void *handle);
|
||||
int32_t mz_win32_sha_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_win32_sha_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
void mz_win32_sha_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_win32_sha_create(void **handle);
|
||||
void mz_win32_sha_delete(void **handle);
|
||||
|
||||
void mz_win32_aes_reset(void *handle);
|
||||
int32_t mz_win32_aes_encrypt(void *handle, uint8_t *buf, int32_t size, int32_t final);
|
||||
int32_t mz_win32_aes_decrypt(void *handle, uint8_t *buf, int32_t size, int32_t final);
|
||||
int32_t mz_win32_aes_set_key(void *handle, const void *key, int32_t key_length);
|
||||
void mz_win32_aes_set_mode(void *handle, int32_t mode);
|
||||
void mz_win32_aes_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_win32_aes_create(void **handle);
|
||||
void mz_win32_aes_delete(void **handle);
|
||||
|
||||
void mz_win32_hmac_reset(void *handle);
|
||||
int32_t mz_win32_hmac_begin(void *handle);
|
||||
int32_t mz_win32_hmac_update(void *handle, const void *buf, int32_t size);
|
||||
int32_t mz_win32_hmac_end(void *handle, uint8_t *digest, int32_t digest_size);
|
||||
int32_t mz_win32_hmac_set_key(void *handle, const void *key, int32_t key_length);
|
||||
void mz_win32_hmac_set_algorithm(void *handle, uint16_t algorithm);
|
||||
void* mz_win32_hmac_create(void **handle);
|
||||
void mz_win32_hmac_delete(void **handle);
|
||||
|
||||
int32_t mz_win32_sign(uint8_t *message, int32_t message_size, const char *cert_path, const char *cert_pwd,
|
||||
const char *timestamp_url, uint8_t **signature, int32_t *signature_size);
|
||||
int32_t mz_win32_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#define mz_os_rename mz_win32_rename
|
||||
#define mz_os_delete mz_win32_delete
|
||||
#define mz_os_file_exists mz_win32_file_exists
|
||||
#define mz_os_get_file_size mz_win32_get_file_size
|
||||
#define mz_os_get_file_date mz_win32_get_file_date
|
||||
#define mz_os_set_file_date mz_win32_set_file_date
|
||||
#define mz_os_get_file_attribs mz_win32_get_file_attribs
|
||||
#define mz_os_set_file_attribs mz_win32_set_file_attribs
|
||||
#define mz_os_make_dir mz_win32_make_dir
|
||||
#define mz_os_open_dir mz_win32_open_dir
|
||||
#define mz_os_read_dir mz_win32_read_dir
|
||||
#define mz_os_close_dir mz_win32_close_dir
|
||||
#define mz_os_is_dir mz_win32_is_dir
|
||||
#define mz_os_ms_time mz_win32_ms_time
|
||||
|
||||
#define mz_os_rand mz_win32_rand
|
||||
#define mz_os_sign mz_win32_sign
|
||||
#define mz_os_sign_verify mz_win32_sign_verify
|
||||
|
||||
#define mz_os_sha_reset mz_win32_sha_reset
|
||||
#define mz_os_sha_begin mz_win32_sha_begin
|
||||
#define mz_os_sha_update mz_win32_sha_update
|
||||
#define mz_os_sha_end mz_win32_sha_end
|
||||
#define mz_os_sha_set_algorithm mz_win32_sha_set_algorithm
|
||||
#define mz_os_sha_create mz_win32_sha_create
|
||||
#define mz_os_sha_delete mz_win32_sha_delete
|
||||
|
||||
#define mz_os_aes_reset mz_win32_aes_reset
|
||||
#define mz_os_aes_encrypt mz_win32_aes_encrypt
|
||||
#define mz_os_aes_decrypt mz_win32_aes_decrypt
|
||||
#define mz_os_aes_set_key mz_win32_aes_set_key
|
||||
#define mz_os_aes_set_mode mz_win32_aes_set_mode
|
||||
#define mz_os_aes_set_algorithm mz_win32_aes_set_algorithm
|
||||
#define mz_os_aes_create mz_win32_aes_create
|
||||
#define mz_os_aes_delete mz_win32_aes_delete
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -50,17 +50,17 @@
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_posix_vtbl = {
|
||||
mz_stream_posix_open,
|
||||
mz_stream_posix_is_open,
|
||||
mz_stream_posix_read,
|
||||
mz_stream_posix_write,
|
||||
mz_stream_posix_tell,
|
||||
mz_stream_posix_seek,
|
||||
mz_stream_posix_close,
|
||||
mz_stream_posix_error,
|
||||
mz_stream_posix_create,
|
||||
mz_stream_posix_delete,
|
||||
static mz_stream_vtbl mz_stream_os_vtbl = {
|
||||
mz_stream_os_open,
|
||||
mz_stream_os_is_open,
|
||||
mz_stream_os_read,
|
||||
mz_stream_os_write,
|
||||
mz_stream_os_tell,
|
||||
mz_stream_os_seek,
|
||||
mz_stream_os_close,
|
||||
mz_stream_os_error,
|
||||
mz_stream_os_create,
|
||||
mz_stream_os_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
|
@ -76,7 +76,7 @@ typedef struct mz_stream_posix_s
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode)
|
||||
int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix *)stream;
|
||||
const char *mode_fopen = NULL;
|
||||
|
|
@ -103,7 +103,7 @@ int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_is_open(void *stream)
|
||||
int32_t mz_stream_os_is_open(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
if (posix->handle == NULL)
|
||||
|
|
@ -111,7 +111,7 @@ int32_t mz_stream_posix_is_open(void *stream)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size)
|
||||
int32_t mz_stream_os_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t read = (int32_t)fread(buf, 1, (size_t)size, posix->handle);
|
||||
|
|
@ -123,7 +123,7 @@ int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size)
|
|||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t mz_stream_os_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t written = (int32_t)fwrite(buf, 1, (size_t)size, posix->handle);
|
||||
|
|
@ -135,7 +135,7 @@ int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size)
|
|||
return written;
|
||||
}
|
||||
|
||||
int64_t mz_stream_posix_tell(void *stream)
|
||||
int64_t mz_stream_os_tell(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int64_t position = ftello64(posix->handle);
|
||||
|
|
@ -147,7 +147,7 @@ int64_t mz_stream_posix_tell(void *stream)
|
|||
return position;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
|
||||
int32_t mz_stream_os_seek(void *stream, int64_t offset, int32_t origin)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t fseek_origin = 0;
|
||||
|
|
@ -176,7 +176,7 @@ int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_close(void *stream)
|
||||
int32_t mz_stream_os_close(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
int32_t closed = 0;
|
||||
|
|
@ -193,13 +193,13 @@ int32_t mz_stream_posix_close(void *stream)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_posix_error(void *stream)
|
||||
int32_t mz_stream_os_error(void *stream)
|
||||
{
|
||||
mz_stream_posix *posix = (mz_stream_posix*)stream;
|
||||
return posix->error;
|
||||
}
|
||||
|
||||
void *mz_stream_posix_create(void **stream)
|
||||
void *mz_stream_os_create(void **stream)
|
||||
{
|
||||
mz_stream_posix *posix = NULL;
|
||||
|
||||
|
|
@ -207,7 +207,7 @@ void *mz_stream_posix_create(void **stream)
|
|||
if (posix != NULL)
|
||||
{
|
||||
memset(posix, 0, sizeof(mz_stream_posix));
|
||||
posix->stream.vtbl = &mz_stream_posix_vtbl;
|
||||
posix->stream.vtbl = &mz_stream_os_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = posix;
|
||||
|
|
@ -215,7 +215,7 @@ void *mz_stream_posix_create(void **stream)
|
|||
return posix;
|
||||
}
|
||||
|
||||
void mz_stream_posix_delete(void **stream)
|
||||
void mz_stream_os_delete(void **stream)
|
||||
{
|
||||
mz_stream_posix *posix = NULL;
|
||||
if (stream == NULL)
|
||||
|
|
@ -226,7 +226,7 @@ void mz_stream_posix_delete(void **stream)
|
|||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_posix_get_interface(void)
|
||||
void *mz_stream_os_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_posix_vtbl;
|
||||
return (void *)&mz_stream_os_vtbl;
|
||||
}
|
||||
|
|
@ -19,9 +19,9 @@
|
|||
#include <windows.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os_win32.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_win32.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
|
|
@ -41,17 +41,17 @@
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
static mz_stream_vtbl mz_stream_win32_vtbl = {
|
||||
mz_stream_win32_open,
|
||||
mz_stream_win32_is_open,
|
||||
mz_stream_win32_read,
|
||||
mz_stream_win32_write,
|
||||
mz_stream_win32_tell,
|
||||
mz_stream_win32_seek,
|
||||
mz_stream_win32_close,
|
||||
mz_stream_win32_error,
|
||||
mz_stream_win32_create,
|
||||
mz_stream_win32_delete,
|
||||
static mz_stream_vtbl mz_stream_os_vtbl = {
|
||||
mz_stream_os_open,
|
||||
mz_stream_os_is_open,
|
||||
mz_stream_os_read,
|
||||
mz_stream_os_write,
|
||||
mz_stream_os_tell,
|
||||
mz_stream_os_seek,
|
||||
mz_stream_os_close,
|
||||
mz_stream_os_error,
|
||||
mz_stream_os_create,
|
||||
mz_stream_os_delete,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
|
@ -67,7 +67,7 @@ typedef struct mz_stream_win32_s
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
||||
int32_t mz_stream_os_open(void *stream, const char *path, int32_t mode)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
uint32_t desired_access = 0;
|
||||
|
|
@ -101,7 +101,7 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
|||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
path_wide = mz_win32_unicode_string_create(path);
|
||||
path_wide = mz_os_unicode_string_create(path);
|
||||
|
||||
#ifdef MZ_WINRT_API
|
||||
win32->handle = CreateFile2W(path_wide, desired_access, share_mode, creation_disposition, NULL);
|
||||
|
|
@ -109,21 +109,21 @@ int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode)
|
|||
win32->handle = CreateFileW(path_wide, desired_access, share_mode, NULL, creation_disposition, flags_attribs, NULL);
|
||||
#endif
|
||||
|
||||
mz_win32_unicode_string_delete(&path_wide);
|
||||
mz_os_unicode_string_delete(&path_wide);
|
||||
|
||||
if (mz_stream_win32_is_open(stream) != MZ_OK)
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
{
|
||||
win32->error = GetLastError();
|
||||
return MZ_STREAM_ERROR;
|
||||
}
|
||||
|
||||
if (mode & MZ_OPEN_MODE_APPEND)
|
||||
return mz_stream_win32_seek(stream, 0, MZ_SEEK_END);
|
||||
return mz_stream_os_seek(stream, 0, MZ_SEEK_END);
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_is_open(void *stream)
|
||||
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)
|
||||
|
|
@ -131,12 +131,12 @@ int32_t mz_stream_win32_is_open(void *stream)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_read(void *stream, void *buf, int32_t size)
|
||||
int32_t mz_stream_os_read(void *stream, void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
uint32_t read = 0;
|
||||
|
||||
if (mz_stream_win32_is_open(stream) != MZ_OK)
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (!ReadFile(win32->handle, buf, size, (DWORD *)&read, NULL))
|
||||
|
|
@ -149,12 +149,12 @@ int32_t mz_stream_win32_read(void *stream, void *buf, int32_t size)
|
|||
return read;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_write(void *stream, const void *buf, int32_t size)
|
||||
int32_t mz_stream_os_write(void *stream, const void *buf, int32_t size)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
int32_t written = 0;
|
||||
|
||||
if (mz_stream_win32_is_open(stream) != MZ_OK)
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
if (!WriteFile(win32->handle, buf, size, (DWORD *)&written, NULL))
|
||||
|
|
@ -167,7 +167,7 @@ int32_t mz_stream_win32_write(void *stream, const void *buf, int32_t size)
|
|||
return written;
|
||||
}
|
||||
|
||||
static int32_t mz_stream_win32_seekinternal(HANDLE handle, LARGE_INTEGER large_pos, LARGE_INTEGER *new_pos, uint32_t move_method)
|
||||
static int32_t mz_stream_os_seekinternal(HANDLE handle, LARGE_INTEGER large_pos, LARGE_INTEGER *new_pos, uint32_t move_method)
|
||||
{
|
||||
#ifdef MZ_WINRT_API
|
||||
return SetFilePointerEx(handle, pos, newPos, dwMoveMethod);
|
||||
|
|
@ -191,30 +191,30 @@ static int32_t mz_stream_win32_seekinternal(HANDLE handle, LARGE_INTEGER large_p
|
|||
#endif
|
||||
}
|
||||
|
||||
int64_t mz_stream_win32_tell(void *stream)
|
||||
int64_t mz_stream_os_tell(void *stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
LARGE_INTEGER large_pos;
|
||||
|
||||
if (mz_stream_win32_is_open(stream) != MZ_OK)
|
||||
if (mz_stream_os_is_open(stream) != MZ_OK)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
large_pos.QuadPart = 0;
|
||||
|
||||
if (mz_stream_win32_seekinternal(win32->handle, large_pos, &large_pos, FILE_CURRENT) != MZ_OK)
|
||||
if (mz_stream_os_seekinternal(win32->handle, large_pos, &large_pos, FILE_CURRENT) != MZ_OK)
|
||||
win32->error = GetLastError();
|
||||
|
||||
return large_pos.QuadPart;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_seek(void *stream, int64_t offset, int32_t origin)
|
||||
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;
|
||||
LARGE_INTEGER large_pos;
|
||||
|
||||
|
||||
if (mz_stream_win32_is_open(stream) == MZ_STREAM_ERROR)
|
||||
if (mz_stream_os_is_open(stream) == MZ_STREAM_ERROR)
|
||||
return MZ_STREAM_ERROR;
|
||||
|
||||
switch (origin)
|
||||
|
|
@ -234,7 +234,7 @@ int32_t mz_stream_win32_seek(void *stream, int64_t offset, int32_t origin)
|
|||
|
||||
large_pos.QuadPart = offset;
|
||||
|
||||
if (mz_stream_win32_seekinternal(win32->handle, large_pos, NULL, move_method) != MZ_OK)
|
||||
if (mz_stream_os_seekinternal(win32->handle, large_pos, NULL, move_method) != MZ_OK)
|
||||
{
|
||||
win32->error = GetLastError();
|
||||
return MZ_STREAM_ERROR;
|
||||
|
|
@ -243,7 +243,7 @@ int32_t mz_stream_win32_seek(void *stream, int64_t offset, int32_t origin)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_close(void *stream)
|
||||
int32_t mz_stream_os_close(void *stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
|
||||
|
|
@ -253,13 +253,13 @@ int32_t mz_stream_win32_close(void *stream)
|
|||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_stream_win32_error(void *stream)
|
||||
int32_t mz_stream_os_error(void *stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = (mz_stream_win32 *)stream;
|
||||
return win32->error;
|
||||
}
|
||||
|
||||
void *mz_stream_win32_create(void **stream)
|
||||
void *mz_stream_os_create(void **stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = NULL;
|
||||
|
||||
|
|
@ -267,7 +267,7 @@ void *mz_stream_win32_create(void **stream)
|
|||
if (win32 != NULL)
|
||||
{
|
||||
memset(win32, 0, sizeof(mz_stream_win32));
|
||||
win32->stream.vtbl = &mz_stream_win32_vtbl;
|
||||
win32->stream.vtbl = &mz_stream_os_vtbl;
|
||||
}
|
||||
if (stream != NULL)
|
||||
*stream = win32;
|
||||
|
|
@ -275,7 +275,7 @@ void *mz_stream_win32_create(void **stream)
|
|||
return win32;
|
||||
}
|
||||
|
||||
void mz_stream_win32_delete(void **stream)
|
||||
void mz_stream_os_delete(void **stream)
|
||||
{
|
||||
mz_stream_win32 *win32 = NULL;
|
||||
if (stream == NULL)
|
||||
|
|
@ -286,7 +286,7 @@ void mz_stream_win32_delete(void **stream)
|
|||
*stream = NULL;
|
||||
}
|
||||
|
||||
void *mz_stream_win32_get_interface(void)
|
||||
void *mz_stream_os_get_interface(void)
|
||||
{
|
||||
return (void *)&mz_stream_win32_vtbl;
|
||||
return (void *)&mz_stream_os_vtbl;
|
||||
}
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/* mz_strm_posix.h -- Stream for filesystem access for posix/linux
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_STREAM_POSIX_H
|
||||
#define MZ_STREAM_POSIX_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_posix_open(void *stream, const char *path, int32_t mode);
|
||||
int32_t mz_stream_posix_is_open(void *stream);
|
||||
int32_t mz_stream_posix_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_posix_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_posix_tell(void *stream);
|
||||
int32_t mz_stream_posix_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_posix_close(void *stream);
|
||||
int32_t mz_stream_posix_error(void *stream);
|
||||
|
||||
void* mz_stream_posix_create(void **stream);
|
||||
void mz_stream_posix_delete(void **stream);
|
||||
|
||||
void* mz_stream_posix_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(MZ_WIN32_API)
|
||||
#define mz_stream_os_open mz_stream_posix_open
|
||||
#define mz_stream_os_is_open mz_stream_posix_is_open
|
||||
#define mz_stream_os_read mz_stream_posix_read
|
||||
#define mz_stream_os_write mz_stream_posix_write
|
||||
#define mz_stream_os_tell mz_stream_posix_tell
|
||||
#define mz_stream_os_seek mz_stream_posix_seek
|
||||
#define mz_stream_os_close mz_stream_posix_close
|
||||
#define mz_stream_os_error mz_stream_posix_error
|
||||
|
||||
#define mz_stream_os_create mz_stream_posix_create
|
||||
#define mz_stream_os_delete mz_stream_posix_delete
|
||||
|
||||
#define mz_stream_os_get_interface \
|
||||
mz_stream_posix_get_interface
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/* mz_sstrm_win32.h -- Stream for filesystem access for windows
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_STREAM_WIN32_H
|
||||
#define MZ_STREAM_WIN32_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_stream_win32_open(void *stream, const char *path, int32_t mode);
|
||||
int32_t mz_stream_win32_is_open(void *stream);
|
||||
int32_t mz_stream_win32_read(void *stream, void *buf, int32_t size);
|
||||
int32_t mz_stream_win32_write(void *stream, const void *buf, int32_t size);
|
||||
int64_t mz_stream_win32_tell(void *stream);
|
||||
int32_t mz_stream_win32_seek(void *stream, int64_t offset, int32_t origin);
|
||||
int32_t mz_stream_win32_close(void *stream);
|
||||
int32_t mz_stream_win32_error(void *stream);
|
||||
|
||||
void* mz_stream_win32_create(void **stream);
|
||||
void mz_stream_win32_delete(void **stream);
|
||||
|
||||
void* mz_stream_win32_get_interface(void);
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#if defined(_WIN32) || defined(MZ_WIN32_API)
|
||||
#define mz_stream_os_open mz_stream_win32_open
|
||||
#define mz_stream_os_is_open mz_stream_win32_is_open
|
||||
#define mz_stream_os_read mz_stream_win32_read
|
||||
#define mz_stream_os_write mz_stream_win32_write
|
||||
#define mz_stream_os_tell mz_stream_win32_tell
|
||||
#define mz_stream_os_seek mz_stream_win32_seek
|
||||
#define mz_stream_os_close mz_stream_win32_close
|
||||
#define mz_stream_os_error mz_stream_win32_error
|
||||
|
||||
#define mz_stream_os_create mz_stream_win32_create
|
||||
#define mz_stream_os_delete mz_stream_win32_delete
|
||||
|
||||
#define mz_stream_os_get_interface \
|
||||
mz_stream_win32_get_interface
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
407
mz_util.c
Normal file
407
mz_util.c
Normal file
|
|
@ -0,0 +1,407 @@
|
|||
/* mz_util.c -- Utility functions
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
Copyright (C) 1998-2010 Gilles Vollant
|
||||
https://www.winimage.com/zLibDll/minizip.html
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include "mz.h"
|
||||
#include "mz_os.h"
|
||||
#include "mz_strm.h"
|
||||
#include "mz_strm_crc32.h"
|
||||
#include "mz_strm_os.h"
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
static uint32_t mz_encoding_codepage437_to_utf8[256] = {
|
||||
0x000000, 0xba98e2, 0xbb98e2, 0xa599e2, 0xa699e2, 0xa399e2, 0xa099e2, 0xa280e2,
|
||||
0x9897e2, 0x8b97e2, 0x9997e2, 0x8299e2, 0x8099e2, 0xaa99e2, 0xab99e2, 0xbc98e2,
|
||||
0xba96e2, 0x8497e2, 0x9586e2, 0xbc80e2, 0x00b6c2, 0x00a7c2, 0xac96e2, 0xa886e2,
|
||||
0x9186e2, 0x9386e2, 0x9286e2, 0x9086e2, 0x9f88e2, 0x9486e2, 0xb296e2, 0xbc96e2,
|
||||
0x000020, 0x000021, 0x000022, 0x000023, 0x000024, 0x000025, 0x000026, 0x000027,
|
||||
0x000028, 0x000029, 0x00002a, 0x00002b, 0x00002c, 0x00002d, 0x00002e, 0x00002f,
|
||||
0x000030, 0x000031, 0x000032, 0x000033, 0x000034, 0x000035, 0x000036, 0x000037,
|
||||
0x000038, 0x000039, 0x00003a, 0x00003b, 0x00003c, 0x00003d, 0x00003e, 0x00003f,
|
||||
0x000040, 0x000041, 0x000042, 0x000043, 0x000044, 0x000045, 0x000046, 0x000047,
|
||||
0x000048, 0x000049, 0x00004a, 0x00004b, 0x00004c, 0x00004d, 0x00004e, 0x00004f,
|
||||
0x000050, 0x000051, 0x000052, 0x000053, 0x000054, 0x000055, 0x000056, 0x000057,
|
||||
0x000058, 0x000059, 0x00005a, 0x00005b, 0x00005c, 0x00005d, 0x00005e, 0x00005f,
|
||||
0x000060, 0x000061, 0x000062, 0x000063, 0x000064, 0x000065, 0x000066, 0x000067,
|
||||
0x000068, 0x000069, 0x00006a, 0x00006b, 0x00006c, 0x00006d, 0x00006e, 0x00006f,
|
||||
0x000070, 0x000071, 0x000072, 0x000073, 0x000074, 0x000075, 0x000076, 0x000077,
|
||||
0x000078, 0x000079, 0x00007a, 0x00007b, 0x00007c, 0x00007d, 0x00007e, 0x828ce2,
|
||||
0x0087c3, 0x00bcc3, 0x00a9c3, 0x00a2c3, 0x00a4c3, 0x00a0c3, 0x00a5c3, 0x00a7c3,
|
||||
0x00aac3, 0x00abc3, 0x00a8c3, 0x00afc3, 0x00aec3, 0x00acc3, 0x0084c3, 0x0085c3,
|
||||
0x0089c3, 0x00a6c3, 0x0086c3, 0x00b4c3, 0x00b6c3, 0x00b2c3, 0x00bbc3, 0x00b9c3,
|
||||
0x00bfc3, 0x0096c3, 0x009cc3, 0x00a2c2, 0x00a3c2, 0x00a5c2, 0xa782e2, 0x0092c6,
|
||||
0x00a1c3, 0x00adc3, 0x00b3c3, 0x00bac3, 0x00b1c3, 0x0091c3, 0x00aac2, 0x00bac2,
|
||||
0x00bfc2, 0x908ce2, 0x00acc2, 0x00bdc2, 0x00bcc2, 0x00a1c2, 0x00abc2, 0x00bbc2,
|
||||
0x9196e2, 0x9296e2, 0x9396e2, 0x8294e2, 0xa494e2, 0xa195e2, 0xa295e2, 0x9695e2,
|
||||
0x9595e2, 0xa395e2, 0x9195e2, 0x9795e2, 0x9d95e2, 0x9c95e2, 0x9b95e2, 0x9094e2,
|
||||
0x9494e2, 0xb494e2, 0xac94e2, 0x9c94e2, 0x8094e2, 0xbc94e2, 0x9e95e2, 0x9f95e2,
|
||||
0x9a95e2, 0x9495e2, 0xa995e2, 0xa695e2, 0xa095e2, 0x9095e2, 0xac95e2, 0xa795e2,
|
||||
0xa895e2, 0xa495e2, 0xa595e2, 0x9995e2, 0x9895e2, 0x9295e2, 0x9395e2, 0xab95e2,
|
||||
0xaa95e2, 0x9894e2, 0x8c94e2, 0x8896e2, 0x8496e2, 0x8c96e2, 0x9096e2, 0x8096e2,
|
||||
0x00b1ce, 0x009fc3, 0x0093ce, 0x0080cf, 0x00a3ce, 0x0083cf, 0x00b5c2, 0x0084cf,
|
||||
0x00a6ce, 0x0098ce, 0x00a9ce, 0x00b4ce, 0x9e88e2, 0x0086cf, 0x00b5ce, 0xa988e2,
|
||||
0xa189e2, 0x00b1c2, 0xa589e2, 0xa489e2, 0xa08ce2, 0xa18ce2, 0x00b7c3, 0x8889e2,
|
||||
0x00b0c2, 0x9988e2, 0x00b7c2, 0x9a88e2, 0xbf81e2, 0x00b2c2, 0xa096e2, 0x00a0c2
|
||||
};
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path)
|
||||
{
|
||||
int32_t path_len = 0;
|
||||
|
||||
if (path == NULL || join == NULL || max_path == 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_len = (int32_t)strlen(path);
|
||||
|
||||
if (path_len == 0)
|
||||
{
|
||||
strncpy(path, join, max_path - 1);
|
||||
path[max_path - 1] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (path[path_len - 1] != '\\' && path[path_len - 1] != '/')
|
||||
strncat(path, "/", max_path - path_len - 1);
|
||||
strncat(path, join, max_path - path_len);
|
||||
}
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case)
|
||||
{
|
||||
while (*path != 0)
|
||||
{
|
||||
switch (*wildcard)
|
||||
{
|
||||
case '*':
|
||||
|
||||
if (*(wildcard + 1) == 0)
|
||||
return MZ_OK;
|
||||
|
||||
while (*path != 0)
|
||||
{
|
||||
if (mz_path_compare_wc(path, (wildcard + 1), ignore_case) == MZ_OK)
|
||||
return MZ_OK;
|
||||
|
||||
path += 1;
|
||||
}
|
||||
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
default:
|
||||
// Ignore differences in path slashes on platforms
|
||||
if ((*path == '\\' && *wildcard == '/') || (*path == '/' && *wildcard == '\\'))
|
||||
break;
|
||||
|
||||
if (ignore_case)
|
||||
{
|
||||
if (tolower(*path) != tolower(*wildcard))
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*path != *wildcard)
|
||||
return MZ_EXIST_ERROR;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
path += 1;
|
||||
wildcard += 1;
|
||||
}
|
||||
|
||||
if ((*wildcard != 0) && (*wildcard != '*'))
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *output, int32_t max_output)
|
||||
{
|
||||
const char *source = path;
|
||||
const char *check = output;
|
||||
char *target = output;
|
||||
|
||||
if (max_output <= 0)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
while (*source != 0 && max_output > 1)
|
||||
{
|
||||
check = source;
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
check += 1;
|
||||
|
||||
if ((source == path) || (check != source))
|
||||
{
|
||||
// Skip double paths
|
||||
if ((*check == '\\') || (*check == '/'))
|
||||
{
|
||||
source += 1;
|
||||
continue;
|
||||
}
|
||||
if ((*check != 0) && (*check == '.'))
|
||||
{
|
||||
check += 1;
|
||||
|
||||
// Remove current directory . if at end of string
|
||||
if ((*check == 0) && (source != path))
|
||||
{
|
||||
// Copy last slash
|
||||
*target = *source;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
source += (check - source);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Remove current directory . if not at end of string
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/'))
|
||||
{
|
||||
// Only proceed if .\ is not entire string
|
||||
if (check[1] != 0 || (path != source))
|
||||
{
|
||||
source += (check - source);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Go to parent directory ..
|
||||
if ((*check != 0) || (*check == '.'))
|
||||
{
|
||||
check += 1;
|
||||
if ((*check == 0) || (*check == '\\' || *check == '/'))
|
||||
{
|
||||
source += (check - source);
|
||||
|
||||
// Search backwards for previous slash
|
||||
if (target != output)
|
||||
{
|
||||
target -= 1;
|
||||
do
|
||||
{
|
||||
if ((*target == '\\') || (*target == '/'))
|
||||
break;
|
||||
|
||||
target -= 1;
|
||||
max_output += 1;
|
||||
}
|
||||
while (target > output);
|
||||
}
|
||||
|
||||
if ((target == output) && (*source != 0))
|
||||
source += 1;
|
||||
if ((*target == '\\' || *target == '/') && (*source == 0))
|
||||
target += 1;
|
||||
|
||||
*target = 0;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*target = *source;
|
||||
|
||||
source += 1;
|
||||
target += 1;
|
||||
max_output -= 1;
|
||||
}
|
||||
|
||||
*target = 0;
|
||||
|
||||
if (*path == 0)
|
||||
return MZ_INTERNAL_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_remove_filename(char *path)
|
||||
{
|
||||
char *path_ptr = NULL;
|
||||
|
||||
if (path == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
path_ptr = path + strlen(path) - 1;
|
||||
|
||||
while (path_ptr > path)
|
||||
{
|
||||
if ((*path_ptr == '/') || (*path_ptr == '\\'))
|
||||
{
|
||||
*path_ptr = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
path_ptr -= 1;
|
||||
}
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename)
|
||||
{
|
||||
const char *match = NULL;
|
||||
|
||||
if (path == NULL || filename == NULL)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
*filename = NULL;
|
||||
|
||||
for (match = path; *match != 0; match += 1)
|
||||
{
|
||||
if ((*match == '\\') || (*match == '/'))
|
||||
*filename = match + 1;
|
||||
}
|
||||
|
||||
if (*filename == NULL)
|
||||
return MZ_EXIST_ERROR;
|
||||
|
||||
return MZ_OK;
|
||||
}
|
||||
|
||||
int32_t mz_dir_make(const char *path)
|
||||
{
|
||||
int32_t err = MZ_OK;
|
||||
int16_t len = 0;
|
||||
char *current_dir = NULL;
|
||||
char *match = NULL;
|
||||
char hold = 0;
|
||||
|
||||
|
||||
len = (int16_t)strlen(path);
|
||||
if (len <= 0)
|
||||
return 0;
|
||||
|
||||
current_dir = (char *)MZ_ALLOC((uint16_t)len + 1);
|
||||
if (current_dir == NULL)
|
||||
return MZ_MEM_ERROR;
|
||||
|
||||
strcpy(current_dir, path);
|
||||
|
||||
if (current_dir[len - 1] == '/')
|
||||
current_dir[len - 1] = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
{
|
||||
match = current_dir + 1;
|
||||
while (1)
|
||||
{
|
||||
while (*match != 0 && *match != '\\' && *match != '/')
|
||||
match += 1;
|
||||
hold = *match;
|
||||
*match = 0;
|
||||
|
||||
err = mz_os_make_dir(current_dir);
|
||||
if (err != MZ_OK)
|
||||
break;
|
||||
if (hold == 0)
|
||||
break;
|
||||
|
||||
*match = hold;
|
||||
match += 1;
|
||||
}
|
||||
}
|
||||
|
||||
MZ_FREE(current_dir);
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc)
|
||||
{
|
||||
void *stream = NULL;
|
||||
void *crc32_stream = NULL;
|
||||
int32_t read = 0;
|
||||
int32_t err = MZ_OK;
|
||||
uint8_t buf[16384];
|
||||
|
||||
mz_stream_os_create(&stream);
|
||||
|
||||
err = mz_stream_os_open(stream, path, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_crc32_create(&crc32_stream);
|
||||
mz_stream_crc32_open(crc32_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
|
||||
mz_stream_set_base(crc32_stream, stream);
|
||||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
do
|
||||
{
|
||||
read = mz_stream_crc32_read(crc32_stream, buf, sizeof(buf));
|
||||
|
||||
if (read < 0)
|
||||
{
|
||||
err = read;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while ((err == MZ_OK) && (read > 0));
|
||||
|
||||
mz_stream_os_close(stream);
|
||||
}
|
||||
|
||||
mz_stream_crc32_close(crc32_stream);
|
||||
*result_crc = mz_stream_crc32_get_value(crc32_stream);
|
||||
mz_stream_crc32_delete(&crc32_stream);
|
||||
|
||||
mz_stream_os_delete(&stream);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t mz_encoding_cp437_to_utf8(const char *source, char *target, int32_t max_target)
|
||||
{
|
||||
uint32_t utf8_char = 0;
|
||||
uint8_t utf8_byte = 0;
|
||||
uint8_t cp437_char = 0;
|
||||
int32_t x = 0;
|
||||
int32_t written = 0;
|
||||
|
||||
// Convert ibm codepage 437 encoding to utf-8
|
||||
while (*source != 0)
|
||||
{
|
||||
cp437_char = (uint8_t)*source;
|
||||
source += 1;
|
||||
utf8_char = mz_encoding_codepage437_to_utf8[cp437_char];
|
||||
for (x = 0; x < 32; x += 8)
|
||||
{
|
||||
utf8_byte = (uint8_t)(utf8_char >> x);
|
||||
if (x > 0 && utf8_byte == 0)
|
||||
continue;
|
||||
if (max_target <= 1)
|
||||
break;
|
||||
target[written] = (char)utf8_byte;
|
||||
written += 1;
|
||||
max_target -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (max_target > 0)
|
||||
{
|
||||
target[written] = 0;
|
||||
written += 1;
|
||||
}
|
||||
|
||||
return written;
|
||||
}
|
||||
|
||||
/***************************************************************************/
|
||||
53
mz_util.h
Normal file
53
mz_util.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/* mz_util.h -- Utility functions
|
||||
Version 2.6.0, October 8, 2018
|
||||
part of the MiniZip project
|
||||
|
||||
Copyright (C) 2010-2018 Nathan Moinvaziri
|
||||
https://github.com/nmoinvaz/minizip
|
||||
|
||||
This program is distributed under the terms of the same license as zlib.
|
||||
See the accompanying LICENSE file for the full text of the license.
|
||||
*/
|
||||
|
||||
#ifndef MZ_UTIL_H
|
||||
#define MZ_UTIL_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
int32_t mz_path_combine(char *path, const char *join, int32_t max_path);
|
||||
// Combines two paths
|
||||
|
||||
int32_t mz_path_compare_wc(const char *path, const char *wildcard, uint8_t ignore_case);
|
||||
// Compare two paths with wildcard
|
||||
|
||||
int32_t mz_path_resolve(const char *path, char *target, int32_t max_target);
|
||||
// Resolves path
|
||||
|
||||
int32_t mz_path_remove_filename(char *path);
|
||||
// Remove the filename from a path
|
||||
|
||||
int32_t mz_path_get_filename(const char *path, const char **filename);
|
||||
// Get the filename from a path
|
||||
|
||||
int32_t mz_dir_make(const char *path);
|
||||
// Creates a directory recursively
|
||||
|
||||
int32_t mz_file_get_crc(const char *path, uint32_t *result_crc);
|
||||
// Gets the crc32 hash of a file
|
||||
|
||||
int32_t mz_encoding_cp437_to_utf8(const char *source, char *target, int32_t max_target);
|
||||
// Converts ibm cp437 encoded string to utf8
|
||||
|
||||
/***************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
12
mz_zip.c
12
mz_zip.c
|
|
@ -27,9 +27,6 @@
|
|||
|
||||
#include "mz.h"
|
||||
#include "mz_strm.h"
|
||||
#ifdef HAVE_AES
|
||||
# include "mz_strm_aes.h"
|
||||
#endif
|
||||
#ifdef HAVE_BZIP2
|
||||
# include "mz_strm_bzip.h"
|
||||
#endif
|
||||
|
|
@ -41,6 +38,9 @@
|
|||
#ifdef HAVE_PKCRYPT
|
||||
# include "mz_strm_pkcrypt.h"
|
||||
#endif
|
||||
#ifdef HAVE_AES
|
||||
# include "mz_strm_wzaes.h"
|
||||
#endif
|
||||
#ifdef HAVE_ZLIB
|
||||
# include "mz_strm_zlib.h"
|
||||
#endif
|
||||
|
|
@ -1335,9 +1335,9 @@ static int32_t mz_zip_entry_open_int(void *handle, uint8_t raw, int16_t compress
|
|||
#ifdef HAVE_AES
|
||||
if (zip->file_info.aes_version)
|
||||
{
|
||||
mz_stream_aes_create(&zip->crypt_stream);
|
||||
mz_stream_aes_set_password(zip->crypt_stream, password);
|
||||
mz_stream_aes_set_encryption_mode(zip->crypt_stream, zip->file_info.aes_encryption_mode);
|
||||
mz_stream_wzaes_create(&zip->crypt_stream);
|
||||
mz_stream_wzaes_set_password(zip->crypt_stream, password);
|
||||
mz_stream_wzaes_set_encryption_mode(zip->crypt_stream, zip->file_info.aes_encryption_mode);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
|
|
|
|||
37
mz_zip_rw.c
37
mz_zip_rw.c
|
|
@ -20,8 +20,10 @@
|
|||
#include "mz_strm.h"
|
||||
#include "mz_strm_buf.h"
|
||||
#include "mz_strm_mem.h"
|
||||
#include "mz_strm_aes.h"
|
||||
#include "mz_strm_os.h"
|
||||
#include "mz_strm_split.h"
|
||||
#include "mz_strm_wzaes.h"
|
||||
#include "mz_util.h"
|
||||
#include "mz_zip.h"
|
||||
|
||||
#include "mz_zip_rw.h"
|
||||
|
|
@ -40,7 +42,7 @@ typedef struct mz_zip_reader_s {
|
|||
void *buffered_stream;
|
||||
void *split_stream;
|
||||
void *mem_stream;
|
||||
void *sha1_stream;
|
||||
void *sha256;
|
||||
mz_zip_file *file_info;
|
||||
const char *pattern;
|
||||
uint8_t pattern_ignore_case;
|
||||
|
|
@ -388,8 +390,8 @@ int32_t mz_zip_reader_entry_open(void *handle)
|
|||
|
||||
if (err == MZ_OK)
|
||||
{
|
||||
mz_stream_sha1_create(&reader->sha1_stream);
|
||||
mz_stream_sha1_open(reader->sha1_stream, NULL, MZ_OPEN_MODE_READ);
|
||||
mz_os_sha_create(&reader->sha256);
|
||||
mz_os_sha_set_algorithm(reader->sha256, MZ_HASH_SHA256);
|
||||
|
||||
if (mz_zip_reader_entry_has_sign(handle) == MZ_OK)
|
||||
err = mz_zip_reader_entry_sign_verify(handle);
|
||||
|
|
@ -412,8 +414,7 @@ int32_t mz_zip_reader_entry_close(void *handle)
|
|||
uint8_t expected_sha1[MZ_HASH_SHA1_SIZE];
|
||||
|
||||
|
||||
mz_stream_sha1_close(reader->sha1_stream);
|
||||
mz_stream_sha1_get_digest(reader->sha1_stream, computed_sha1, sizeof(computed_sha1));
|
||||
mz_os_sha_end(reader->sha256, computed_sha1, sizeof(computed_sha1));
|
||||
|
||||
err_hash = mz_zip_reader_entry_get_hash(handle, MZ_HASH_SHA1, expected_sha1, sizeof(expected_sha1));
|
||||
err = mz_zip_entry_close(reader->zip_handle);
|
||||
|
|
@ -425,7 +426,7 @@ int32_t mz_zip_reader_entry_close(void *handle)
|
|||
err = MZ_CRC_ERROR;
|
||||
}
|
||||
|
||||
mz_stream_sha1_delete(&reader->sha1_stream);
|
||||
mz_os_sha_delete(&reader->sha256);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
|
@ -435,7 +436,7 @@ int32_t mz_zip_reader_entry_read(void *handle, void *buf, int32_t len)
|
|||
int32_t read = 0;
|
||||
read = mz_zip_entry_read(reader->zip_handle, buf, len);
|
||||
if (read > 0)
|
||||
mz_stream_sha1_read(reader->sha1_stream, buf, read);
|
||||
mz_os_sha_update(reader->sha256, buf, read);
|
||||
return read;
|
||||
}
|
||||
|
||||
|
|
@ -937,7 +938,7 @@ typedef struct mz_zip_writer_s {
|
|||
void *file_stream;
|
||||
void *buffered_stream;
|
||||
void *split_stream;
|
||||
void *sha1_stream;
|
||||
void *sha256;
|
||||
void *mem_stream;
|
||||
void *file_extra_stream;
|
||||
mz_zip_file file_info;
|
||||
|
|
@ -1215,8 +1216,8 @@ int32_t mz_zip_writer_entry_open(void *handle, mz_zip_file *file_info)
|
|||
}
|
||||
|
||||
// Start calculating sha1
|
||||
mz_stream_sha1_create(&writer->sha1_stream);
|
||||
mz_stream_sha1_open(writer->sha1_stream, NULL, MZ_OPEN_MODE_WRITE);
|
||||
mz_os_sha_create(&writer->sha256);
|
||||
mz_os_sha_set_algorithm(writer->sha256, MZ_HASH_SHA256);
|
||||
|
||||
// Open entry in zip
|
||||
err = mz_zip_entry_write_open(writer->zip_handle, &writer->file_info, writer->compress_level, writer->raw, password);
|
||||
|
|
@ -1234,10 +1235,7 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
|||
uint8_t sha1[MZ_HASH_SHA1_SIZE];
|
||||
|
||||
|
||||
if (mz_stream_sha1_is_open(writer->sha1_stream) == MZ_OK)
|
||||
mz_stream_sha1_close(writer->sha1_stream);
|
||||
|
||||
mz_stream_sha1_get_digest(writer->sha1_stream, sha1, sizeof(sha1));
|
||||
mz_os_sha_end(writer->sha256, sha1, sizeof(sha1));
|
||||
|
||||
// Copy extrafield so we can append our own fields before close
|
||||
mz_stream_mem_create(&writer->file_extra_stream);
|
||||
|
|
@ -1274,7 +1272,7 @@ int32_t mz_zip_writer_entry_close(void *handle)
|
|||
else
|
||||
err = mz_zip_entry_close(writer->zip_handle);
|
||||
|
||||
mz_stream_sha1_delete(&writer->sha1_stream);
|
||||
mz_os_sha_delete(&writer->sha256);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
|
@ -1285,7 +1283,7 @@ int32_t mz_zip_writer_entry_write(void *handle, const void *buf, int32_t len)
|
|||
int32_t written = 0;
|
||||
written = mz_zip_entry_write(writer->zip_handle, buf, len);
|
||||
if (written > 0)
|
||||
mz_stream_sha1_write(writer->sha1_stream, buf, written);
|
||||
mz_os_sha_update(writer->sha256, buf, written);
|
||||
return written;
|
||||
}
|
||||
|
||||
|
|
@ -1303,10 +1301,7 @@ int32_t mz_zip_writer_entry_sign(void *handle, const char *cert_path, const char
|
|||
if (writer == NULL || mz_zip_entry_is_open(writer->zip_handle) != MZ_OK)
|
||||
return MZ_PARAM_ERROR;
|
||||
|
||||
if (mz_stream_sha1_is_open(writer->sha1_stream) == MZ_OK)
|
||||
mz_stream_sha1_close(writer->sha1_stream);
|
||||
|
||||
mz_stream_sha1_get_digest(writer->sha1_stream, sha1, sizeof(sha1));
|
||||
mz_os_sha_end(writer->sha256, sha1, sizeof(sha1));
|
||||
|
||||
if (err == MZ_OK)
|
||||
err = mz_os_sign(sha1, sizeof(sha1), writer->cert_path, writer->cert_pwd, writer->timestamp_url,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue