Skip to content

Commit

Permalink
for windows ZIP_ENABLE_SHARABLE_FILE_OPEN (#328)
Browse files Browse the repository at this point in the history
Co-authored-by: Xiaolong Cao <72238371+visla-dragon@users.noreply.github.com>
  • Loading branch information
appledragon and visla-dragon committed Jan 5, 2024
1 parent a93ea8f commit 550905d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/miniz.h
Original file line number Diff line number Diff line change
Expand Up @@ -4968,20 +4968,36 @@ 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;
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
pFile = _wfopen(wFilename, wMode);
#else
errno_t err = _wfopen_s(&pFile, wFilename, wMode);
#endif
free(wFilename);
free(wMode);
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
return pFile;
#else
return err ? NULL : pFile;
#endif
}

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;
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
pFile = _wfreopen(wPath, wMode, pStream);
#else
errno_t err = _wfreopen_s(&pFile, wPath, wMode, pStream);
#endif
free(wPath);
free(wMode);
#ifdef ZIP_ENABLE_SHARABLE_FILE_OPEN
return pFile;
#else
return err ? NULL : pFile;
#endif
}

static int mz_stat64(const char *path, struct __stat64 *buffer) {
Expand Down

0 comments on commit 550905d

Please sign in to comment.