Skip to content

Commit c95cddd

Browse files
committed
Fix minizip build on Windows
1 parent c1c77b5 commit c95cddd

File tree

2 files changed

+21
-31
lines changed

2 files changed

+21
-31
lines changed

src/vendored/zip/miniz.h

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4968,6 +4968,7 @@ extern "C" {
49684968

49694969
#if defined(_MSC_VER) || defined(__MINGW64__) || defined(__MINGW32__)
49704970

4971+
#if 0 // let's not use anything from windows.h if we can help it.
49714972
#ifndef WIN32_LEAN_AND_MEAN
49724973
#define WIN32_LEAN_AND_MEAN
49734974
#endif
@@ -4978,25 +4979,15 @@ extern "C" {
49784979
#define NOMINMAX
49794980
#endif
49804981
#include <windows.h>
4981-
4982-
static WCHAR *mz_utf8z_to_widechar(const char *str) {
4983-
int reqChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
4984-
WCHAR *wStr = (WCHAR *)malloc(reqChars * sizeof(WCHAR));
4985-
MultiByteToWideChar(CP_UTF8, 0, str, -1, wStr, reqChars);
4986-
return wStr;
4987-
}
4982+
#endif // 0
49884983

49894984
static FILE *mz_fopen(const char *pFilename, const char *pMode) {
4990-
WCHAR *wFilename = mz_utf8z_to_widechar(pFilename);
4991-
WCHAR *wMode = mz_utf8z_to_widechar(pMode);
49924985
FILE *pFile = NULL;
49934986
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
4994-
pFile = _wfopen(wFilename, wMode);
4987+
pFile = fopen(pFilename, pMode);
49954988
#else
4996-
errno_t err = _wfopen_s(&pFile, wFilename, wMode);
4989+
errno_t err = fopen_s(&pFile, pFilename, pMode);
49974990
#endif
4998-
free(wFilename);
4999-
free(wMode);
50004991
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
50014992
return pFile;
50024993
#else
@@ -5005,16 +4996,12 @@ static FILE *mz_fopen(const char *pFilename, const char *pMode) {
50054996
}
50064997

50074998
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) {
5008-
WCHAR *wPath = mz_utf8z_to_widechar(pPath);
5009-
WCHAR *wMode = mz_utf8z_to_widechar(pMode);
50104999
FILE *pFile = NULL;
50115000
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
5012-
pFile = _wfreopen(wPath, wMode, pStream);
5001+
pFile = _wfreopen(pPath, pMode, pStream);
50135002
#else
5014-
errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream);
5003+
errno_t err = freopen_s(&pFile, pPath, pMode, pStream);
50155004
#endif
5016-
free(wPath);
5017-
free(wMode);
50185005
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
50195006
return pFile;
50205007
#else
@@ -5024,24 +5011,18 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream) {
50245011

50255012
#if defined(__MINGW32__)
50265013
static int mz_stat(const char *path, struct _stat *buffer) {
5027-
WCHAR *wPath = mz_utf8z_to_widechar(path);
5028-
int res = _wstat(wPath, buffer);
5029-
free(wPath);
5014+
int res = stat(path, buffer);
50305015
return res;
50315016
}
50325017
#else
50335018
static int mz_stat64(const char *path, struct __stat64 *buffer) {
5034-
WCHAR *wPath = mz_utf8z_to_widechar(path);
5035-
int res = _wstat64(wPath, buffer);
5036-
free(wPath);
5019+
int res = _stat64(path, buffer);
50375020
return res;
50385021
}
50395022
#endif
50405023

50415024
static int mz_mkdir(const char *pDirname) {
5042-
WCHAR *wDirname = mz_utf8z_to_widechar(pDirname);
5043-
int res = _wmkdir(wDirname);
5044-
free(wDirname);
5025+
int res = mkdir(pDirname);
50455026
return res;
50465027
}
50475028

@@ -6608,6 +6589,11 @@ mz_bool mz_zip_reader_locate_file_v2(mz_zip_archive *pZip, const char *pName,
66086589
return mz_zip_set_error(pZip, MZ_ZIP_FILE_NOT_FOUND);
66096590
}
66106591

6592+
#ifdef _MSC_VER
6593+
#pragma warning(push)
6594+
#pragma warning(disable : 4127) /* conditional expression is constant */
6595+
#endif
6596+
66116597
static mz_bool mz_zip_reader_extract_to_mem_no_alloc1(
66126598
mz_zip_archive *pZip, mz_uint file_index, void *pBuf, size_t buf_size,
66136599
mz_uint flags, void *pUser_read_buf, size_t user_read_buf_size,
@@ -7904,6 +7890,10 @@ static size_t mz_zip_heap_write_func(void *pOpaque, mz_uint64 file_ofs,
79047890
return n;
79057891
}
79067892

7893+
#ifdef _MSC_VER
7894+
#pragma warning(pop) /* conditional expression is constant */
7895+
#endif
7896+
79077897
static mz_bool mz_zip_writer_end_internal(mz_zip_archive *pZip,
79087898
mz_bool set_last_error) {
79097899
mz_zip_internal_state *pState;

src/vendored/zip/zip.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,12 +1167,12 @@ static int _zip_entry_open(struct zip_t *zip, const char *entryname,
11671167
memset(zip->entry.header, 0, MZ_ZIP_LOCAL_DIR_HEADER_SIZE * sizeof(mz_uint8));
11681168
zip->entry.method = level ? MZ_DEFLATED : 0;
11691169

1170+
#if defined(_WIN32) || defined(__WIN32__) || defined(DJGPP)
1171+
zip->entry.external_attr = 0;
1172+
#else
11701173
// UNIX or APPLE
1171-
#if MZ_PLATFORM == 3 || MZ_PLATFORM == 19
11721174
// regular file with rw-r--r-- permissions
11731175
zip->entry.external_attr = (mz_uint32)(0100644) << 16;
1174-
#else
1175-
zip->entry.external_attr = 0;
11761176
#endif
11771177

11781178
num_alignment_padding_bytes =

0 commit comments

Comments
 (0)