Merge pull request #203 from prezi/prezi-patch-2
Support for unicode characters in paths and filenames on windows
This commit is contained in:
commit
18da352921
41
miniz_zip.c
41
miniz_zip.c
@ -40,19 +40,48 @@ extern "C" {
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(__MINGW64__)
|
#if defined(_MSC_VER) || defined(__MINGW64__)
|
||||||
|
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <Windows.h>
|
||||||
|
|
||||||
|
static WCHAR* mz_utf8z_to_widechar(const char* str)
|
||||||
|
{
|
||||||
|
int reqChars = MultiByteToWideChar(CP_UTF8, 0, str, -1, NULL, 0);
|
||||||
|
WCHAR* wStr = (WCHAR*)malloc(reqChars * sizeof(WCHAR));
|
||||||
|
MultiByteToWideChar(CP_UTF8, 0, str, -1, wStr, sizeof(WCHAR) * reqChars);
|
||||||
|
return wStr;
|
||||||
|
}
|
||||||
|
|
||||||
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
static FILE *mz_fopen(const char *pFilename, const char *pMode)
|
||||||
{
|
{
|
||||||
|
WCHAR* wFilename = mz_utf8z_to_widechar(pFilename);
|
||||||
|
WCHAR* wMode = mz_utf8z_to_widechar(pMode);
|
||||||
FILE* pFile = NULL;
|
FILE* pFile = NULL;
|
||||||
fopen_s(&pFile, pFilename, pMode);
|
errno_t err = _wfopen_s(&pFile, wFilename, wMode);
|
||||||
return pFile;
|
free(wFilename);
|
||||||
|
free(wMode);
|
||||||
|
return err ? NULL : pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
||||||
{
|
{
|
||||||
|
WCHAR* wPath = mz_utf8z_to_widechar(pPath);
|
||||||
|
WCHAR* wMode = mz_utf8z_to_widechar(pMode);
|
||||||
FILE* pFile = NULL;
|
FILE* pFile = NULL;
|
||||||
if (freopen_s(&pFile, pPath, pMode, pStream))
|
errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream);
|
||||||
return NULL;
|
free(wPath);
|
||||||
return pFile;
|
free(wMode);
|
||||||
|
return err ? NULL : pFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int mz_stat64(const char *path, struct __stat64 *buffer)
|
||||||
|
{
|
||||||
|
WCHAR* wPath = mz_utf8z_to_widechar(path);
|
||||||
|
int res = _wstat64(wPath, buffer);
|
||||||
|
free(wPath);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef MINIZ_NO_TIME
|
#ifndef MINIZ_NO_TIME
|
||||||
#include <sys/utime.h>
|
#include <sys/utime.h>
|
||||||
#endif
|
#endif
|
||||||
@ -63,7 +92,7 @@ static FILE *mz_freopen(const char *pPath, const char *pMode, FILE *pStream)
|
|||||||
#define MZ_FTELL64 _ftelli64
|
#define MZ_FTELL64 _ftelli64
|
||||||
#define MZ_FSEEK64 _fseeki64
|
#define MZ_FSEEK64 _fseeki64
|
||||||
#define MZ_FILE_STAT_STRUCT _stat64
|
#define MZ_FILE_STAT_STRUCT _stat64
|
||||||
#define MZ_FILE_STAT _stat64
|
#define MZ_FILE_STAT mz_stat64
|
||||||
#define MZ_FFLUSH fflush
|
#define MZ_FFLUSH fflush
|
||||||
#define MZ_FREOPEN mz_freopen
|
#define MZ_FREOPEN mz_freopen
|
||||||
#define MZ_DELETE_FILE remove
|
#define MZ_DELETE_FILE remove
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user