2012-01-21 14:53:44 -07:00
|
|
|
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
2012-07-14 16:32:10 -07:00
|
|
|
Version 1.1, February 14h, 2010
|
|
|
|
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-07-14 16:32:10 -07:00
|
|
|
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-07-14 16:32:10 -07:00
|
|
|
Modifications for Zip64 support
|
|
|
|
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
2012-01-21 14:53:44 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2012-10-21 15:20:13 -07:00
|
|
|
#include <tchar.h>
|
2012-01-21 14:53:44 -07:00
|
|
|
|
|
|
|
#include "zlib.h"
|
|
|
|
#include "ioapi.h"
|
|
|
|
#include "iowin32.h"
|
|
|
|
|
|
|
|
#ifndef INVALID_HANDLE_VALUE
|
|
|
|
#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef INVALID_SET_FILE_POINTER
|
|
|
|
#define INVALID_SET_FILE_POINTER ((DWORD)-1)
|
|
|
|
#endif
|
|
|
|
|
2014-01-07 18:58:43 -07:00
|
|
|
/*#ifndef IOWIN32_USING_WINRT_API
|
|
|
|
#define IOWIN32_USING_WINRT_API
|
|
|
|
#endif*/
|
2014-01-04 22:23:51 -07:00
|
|
|
|
2012-01-21 14:53:44 -07:00
|
|
|
voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
|
|
|
|
uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
|
|
|
|
uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
|
|
|
|
ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
|
|
|
|
long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
|
|
|
|
int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
|
|
|
|
int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HANDLE hf;
|
|
|
|
int error;
|
2012-01-21 15:10:18 -07:00
|
|
|
void *filename;
|
|
|
|
int filenameLength;
|
2012-01-21 14:53:44 -07:00
|
|
|
} WIN32FILE_IOWIN;
|
|
|
|
|
|
|
|
|
|
|
|
static void win32_translate_open_mode(int mode,
|
|
|
|
DWORD* lpdwDesiredAccess,
|
|
|
|
DWORD* lpdwCreationDisposition,
|
|
|
|
DWORD* lpdwShareMode,
|
|
|
|
DWORD* lpdwFlagsAndAttributes)
|
|
|
|
{
|
|
|
|
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
|
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER) == ZLIB_FILEFUNC_MODE_READ)
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
*lpdwDesiredAccess = GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = OPEN_EXISTING;
|
|
|
|
*lpdwShareMode = FILE_SHARE_READ;
|
|
|
|
}
|
|
|
|
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
|
|
|
{
|
|
|
|
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = OPEN_EXISTING;
|
|
|
|
}
|
|
|
|
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
|
|
|
{
|
|
|
|
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = CREATE_ALWAYS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static voidpf win32_build_iowin(HANDLE hFile)
|
|
|
|
{
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
|
|
|
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
|
|
|
|
{
|
2012-01-21 15:10:18 -07:00
|
|
|
iowin = (WIN32FILE_IOWIN *)malloc(sizeof(WIN32FILE_IOWIN));
|
2012-10-25 01:48:11 -07:00
|
|
|
if (iowin == NULL)
|
2012-01-21 15:10:18 -07:00
|
|
|
{
|
2012-01-21 14:53:44 -07:00
|
|
|
CloseHandle(hFile);
|
2012-01-21 15:10:18 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(iowin, 0, sizeof(WIN32FILE_IOWIN));
|
|
|
|
iowin->hf = hFile;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
2012-01-21 15:10:18 -07:00
|
|
|
return (voidpf)iowin;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
2014-01-04 22:23:51 -07:00
|
|
|
voidpf ZCALLBACK win32_open64_file_func (voidpf opaque, const void* filename, int mode)
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
|
|
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
|
|
|
HANDLE hFile = NULL;
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
|
2014-01-04 22:23:51 -07:00
|
|
|
|
|
|
|
if ((filename != NULL) && (dwDesiredAccess != 0))
|
|
|
|
{
|
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
#ifdef UNICODE
|
|
|
|
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
|
|
|
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
|
|
|
|
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#endif
|
|
|
|
#else
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2014-01-04 22:23:51 -07:00
|
|
|
#endif
|
|
|
|
}
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-01-21 15:10:18 -07:00
|
|
|
iowin = win32_build_iowin(hFile);
|
|
|
|
if (iowin == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin->filenameLength = _tcslen(filename) + 1;
|
|
|
|
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(TCHAR));
|
|
|
|
_tcsncpy(iowin->filename, filename, iowin->filenameLength);
|
|
|
|
return iowin;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-04 22:23:51 -07:00
|
|
|
voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque, const void* filename, int mode)
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes ;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if ((filename != NULL) && (dwDesiredAccess != 0))
|
2014-01-04 22:23:51 -07:00
|
|
|
{
|
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
|
|
|
|
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2014-01-04 22:23:51 -07:00
|
|
|
#endif
|
|
|
|
}
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-01-21 15:10:18 -07:00
|
|
|
iowin = win32_build_iowin(hFile);
|
|
|
|
if (iowin == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin->filenameLength = strlen(filename) + 1;
|
|
|
|
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(char));
|
|
|
|
strncpy(iowin->filename, filename, iowin->filenameLength);
|
|
|
|
return iowin;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if ((filename != NULL) && (dwDesiredAccess != 0))
|
2014-01-04 22:23:51 -07:00
|
|
|
{
|
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2014-01-04 22:23:51 -07:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-21 15:10:18 -07:00
|
|
|
iowin = win32_build_iowin(hFile);
|
|
|
|
if (iowin == NULL)
|
|
|
|
return NULL;
|
|
|
|
if (iowin->filename == NULL)
|
|
|
|
{
|
|
|
|
iowin->filenameLength = wcslen(filename) + 1;
|
|
|
|
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(WCHAR));
|
|
|
|
wcsncpy(iowin->filename, filename, iowin->filenameLength);
|
|
|
|
}
|
|
|
|
return iowin;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
DWORD dwDesiredAccess, dwCreationDisposition, dwShareMode, dwFlagsAndAttributes ;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
win32_translate_open_mode(mode, &dwDesiredAccess, &dwCreationDisposition, &dwShareMode, &dwFlagsAndAttributes);
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if ((filename != NULL) && (dwDesiredAccess != 0))
|
2014-01-04 22:23:51 -07:00
|
|
|
{
|
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
#ifdef UNICODE
|
|
|
|
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
|
|
|
WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, (const char*)filename, -1, filenameW, FILENAME_MAX + 0x200);
|
|
|
|
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#endif
|
|
|
|
#else
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2014-01-04 22:23:51 -07:00
|
|
|
#endif
|
|
|
|
}
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-01-21 15:10:18 -07:00
|
|
|
iowin = win32_build_iowin(hFile);
|
|
|
|
if (iowin == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin->filenameLength = _tcslen(filename) + 1;
|
|
|
|
iowin->filename = (void*)malloc(iowin->filenameLength * sizeof(TCHAR));
|
|
|
|
_tcsncpy(iowin->filename, filename, iowin->filenameLength);
|
|
|
|
return iowin;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
2012-01-21 15:10:18 -07:00
|
|
|
voidpf ZCALLBACK win32_opendisk64_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
|
|
{
|
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
|
|
|
TCHAR *diskFilename = NULL;
|
|
|
|
voidpf ret = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin = (WIN32FILE_IOWIN*)stream;
|
|
|
|
diskFilename = (TCHAR*)malloc(iowin->filenameLength * sizeof(TCHAR));
|
|
|
|
_tcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
|
|
|
|
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
|
|
|
|
{
|
|
|
|
if (diskFilename[i] != _T('.'))
|
|
|
|
continue;
|
|
|
|
_sntprintf(&diskFilename[i], iowin->filenameLength - i, _T(".z%02d"), number_disk + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 0)
|
|
|
|
ret = win32_open64_file_func(opaque, diskFilename, mode);
|
|
|
|
free(diskFilename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_opendisk64_file_funcW (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
|
|
{
|
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
|
|
|
WCHAR *diskFilename = NULL;
|
|
|
|
voidpf ret = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin = (WIN32FILE_IOWIN*)stream;
|
|
|
|
diskFilename = (WCHAR*)malloc((iowin->filenameLength + 10) * sizeof(WCHAR));
|
|
|
|
wcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
|
|
|
|
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
|
|
|
|
{
|
|
|
|
if (diskFilename[i] != L'.')
|
|
|
|
continue;
|
|
|
|
_snwprintf(&diskFilename[i], (iowin->filenameLength + 10) - i, L".z%02d", number_disk + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 0)
|
|
|
|
ret = win32_open64_file_funcW(opaque, diskFilename, mode);
|
|
|
|
free(diskFilename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_opendisk64_file_funcA (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
|
|
{
|
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
|
|
|
char *diskFilename = NULL;
|
|
|
|
voidpf ret = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin = (WIN32FILE_IOWIN*)stream;
|
|
|
|
diskFilename = (char*)malloc(iowin->filenameLength * sizeof(char));
|
|
|
|
strncpy(diskFilename, iowin->filename, iowin->filenameLength);
|
|
|
|
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
|
|
|
|
{
|
|
|
|
if (diskFilename[i] != '.')
|
|
|
|
continue;
|
|
|
|
_snprintf(&diskFilename[i], iowin->filenameLength - i, ".z%02d", number_disk + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 0)
|
|
|
|
ret = win32_open64_file_funcA(opaque, diskFilename, mode);
|
|
|
|
free(diskFilename);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_opendisk_file_func (voidpf opaque, voidpf stream, int number_disk, int mode)
|
|
|
|
{
|
|
|
|
WIN32FILE_IOWIN *iowin = NULL;
|
|
|
|
TCHAR *diskFilename = NULL;
|
|
|
|
voidpf ret = NULL;
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
if (stream == NULL)
|
|
|
|
return NULL;
|
|
|
|
iowin = (WIN32FILE_IOWIN*)stream;
|
|
|
|
diskFilename = (TCHAR*)malloc(iowin->filenameLength * sizeof(TCHAR));
|
|
|
|
_tcsncpy(diskFilename, iowin->filename, iowin->filenameLength);
|
|
|
|
for (i = iowin->filenameLength - 1; i >= 0; i -= 1)
|
|
|
|
{
|
|
|
|
if (diskFilename[i] != _T('.'))
|
|
|
|
continue;
|
|
|
|
_sntprintf(&diskFilename[i], iowin->filenameLength - i, _T(".z%02d"), number_disk + 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i >= 0)
|
|
|
|
ret = win32_open_file_func(opaque, diskFilename, mode);
|
|
|
|
free(diskFilename);
|
|
|
|
return ret;
|
|
|
|
}
|
2012-01-21 14:53:44 -07:00
|
|
|
|
|
|
|
uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
|
|
|
|
{
|
2012-10-25 01:48:11 -07:00
|
|
|
uLong ret = 0;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
|
|
|
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
if (dwErr == ERROR_HANDLE_EOF)
|
|
|
|
dwErr = 0;
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
|
|
|
|
{
|
2012-10-25 01:48:11 -07:00
|
|
|
uLong ret = 0;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
|
|
|
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
if (dwErr == ERROR_HANDLE_EOF)
|
|
|
|
dwErr = 0;
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-04 22:23:51 -07:00
|
|
|
static BOOL win32_setfilepointer_internal(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
|
|
|
|
{
|
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
|
|
|
|
#else
|
|
|
|
LONG lHigh = pos.HighPart;
|
|
|
|
BOOL ret = TRUE;
|
2014-01-07 09:12:37 -07:00
|
|
|
DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
|
2014-01-04 22:28:11 -07:00
|
|
|
if ((dwNewPos == INVALID_SET_FILE_POINTER) && (GetLastError() != NO_ERROR))
|
2014-01-04 22:23:51 -07:00
|
|
|
ret = FALSE;
|
|
|
|
if ((newPos != NULL) && (ret))
|
|
|
|
{
|
|
|
|
newPos->LowPart = dwNewPos;
|
|
|
|
newPos->HighPart = lHigh;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-01-21 14:53:44 -07:00
|
|
|
long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
|
|
|
|
{
|
2012-10-25 01:48:11 -07:00
|
|
|
long ret = -1;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
2012-01-21 14:53:44 -07:00
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
2014-01-04 22:23:51 -07:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
if (!win32_setfilepointer_internal(hFile, pos, &pos, FILE_CURRENT))
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
2014-01-04 22:23:51 -07:00
|
|
|
ret = (long)pos.LowPart;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
|
|
|
|
{
|
2012-10-25 01:48:11 -07:00
|
|
|
ZPOS64_T ret = (ZPOS64_T)-1;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
|
|
|
|
|
|
|
if (hFile)
|
|
|
|
{
|
2014-01-04 22:23:51 -07:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
if (!win32_setfilepointer_internal(hFile, pos, &pos, FILE_CURRENT))
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
ret = (ZPOS64_T)-1;
|
|
|
|
}
|
|
|
|
else
|
2014-01-04 22:23:51 -07:00
|
|
|
ret = pos.QuadPart;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
|
|
|
|
{
|
2013-12-20 13:59:33 -07:00
|
|
|
DWORD dwMoveMethod = 0xFFFFFFFF;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
long ret = -1;
|
2013-12-20 13:59:33 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
2013-12-20 13:59:33 -07:00
|
|
|
|
2012-01-21 14:53:44 -07:00
|
|
|
switch (origin)
|
|
|
|
{
|
2013-12-20 13:59:33 -07:00
|
|
|
case ZLIB_FILEFUNC_SEEK_CUR:
|
|
|
|
dwMoveMethod = FILE_CURRENT;
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_END:
|
|
|
|
dwMoveMethod = FILE_END;
|
|
|
|
break;
|
|
|
|
case ZLIB_FILEFUNC_SEEK_SET:
|
|
|
|
dwMoveMethod = FILE_BEGIN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -1;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
2014-01-04 22:23:51 -07:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
if (!win32_setfilepointer_internal(hFile, pos, NULL, dwMoveMethod))
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error=(int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-20 13:59:33 -07:00
|
|
|
ret = 0;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
|
|
|
|
{
|
2013-12-20 13:59:33 -07:00
|
|
|
DWORD dwMoveMethod = 0xFFFFFFFF;
|
2012-01-21 14:53:44 -07:00
|
|
|
HANDLE hFile = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
long ret = -1;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream != NULL)
|
2012-01-21 14:53:44 -07:00
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
|
|
|
|
|
|
|
switch (origin)
|
|
|
|
{
|
2013-12-20 13:59:33 -07:00
|
|
|
case ZLIB_FILEFUNC_SEEK_CUR:
|
2012-01-21 14:53:44 -07:00
|
|
|
dwMoveMethod = FILE_CURRENT;
|
|
|
|
break;
|
2013-12-20 13:59:33 -07:00
|
|
|
case ZLIB_FILEFUNC_SEEK_END:
|
2012-01-21 14:53:44 -07:00
|
|
|
dwMoveMethod = FILE_END;
|
|
|
|
break;
|
2013-12-20 13:59:33 -07:00
|
|
|
case ZLIB_FILEFUNC_SEEK_SET:
|
2012-01-21 14:53:44 -07:00
|
|
|
dwMoveMethod = FILE_BEGIN;
|
|
|
|
break;
|
2013-12-20 13:59:33 -07:00
|
|
|
default:
|
|
|
|
return -1;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hFile)
|
|
|
|
{
|
2014-01-04 22:23:51 -07:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = offset;
|
|
|
|
if (!win32_setfilepointer_internal(hFile, pos, NULL, dwMoveMethod))
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
2012-10-25 01:48:11 -07:00
|
|
|
((WIN32FILE_IOWIN*)stream)->error = (int)dwErr;
|
2012-01-21 14:53:44 -07:00
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
2013-12-20 13:59:33 -07:00
|
|
|
ret = 0;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
|
|
|
|
{
|
2012-01-21 15:10:18 -07:00
|
|
|
WIN32FILE_IOWIN* iowin = NULL;
|
2012-10-25 01:48:11 -07:00
|
|
|
int ret = -1;
|
2012-01-21 14:53:44 -07:00
|
|
|
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream == NULL)
|
2012-01-21 15:10:18 -07:00
|
|
|
return ret;
|
|
|
|
iowin = ((WIN32FILE_IOWIN*)stream);
|
|
|
|
if (iowin->filename != NULL)
|
|
|
|
free(iowin->filename);
|
|
|
|
if (iowin->hf != NULL)
|
|
|
|
{
|
|
|
|
CloseHandle(iowin->hf);
|
|
|
|
ret=0;
|
2012-01-21 14:53:44 -07:00
|
|
|
}
|
2012-01-21 15:10:18 -07:00
|
|
|
free(stream);
|
2012-01-21 14:53:44 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-20 14:02:40 -07:00
|
|
|
int ZCALLBACK win32_error_file_func (voidpf opaque, voidpf stream)
|
2012-01-21 14:53:44 -07:00
|
|
|
{
|
2013-12-20 13:59:33 -07:00
|
|
|
int ret = -1;
|
2012-10-25 01:48:11 -07:00
|
|
|
if (stream == NULL)
|
2012-01-21 15:10:18 -07:00
|
|
|
return ret;
|
2012-10-25 01:48:11 -07:00
|
|
|
ret = ((WIN32FILE_IOWIN*)stream)->error;
|
2012-01-21 14:53:44 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
2012-01-21 15:10:18 -07:00
|
|
|
pzlib_filefunc_def->zopendisk_file = win32_opendisk_file_func;
|
2012-01-21 14:53:44 -07:00
|
|
|
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
|
|
|
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
|
|
|
pzlib_filefunc_def->ztell_file = win32_tell_file_func;
|
|
|
|
pzlib_filefunc_def->zseek_file = win32_seek_file_func;
|
|
|
|
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
|
|
|
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
|
2012-01-21 15:10:18 -07:00
|
|
|
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_func;
|
2012-01-21 14:53:44 -07:00
|
|
|
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
|
|
|
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
|
|
|
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
|
|
|
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
|
|
|
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
|
|
|
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def)
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA;
|
2012-01-21 15:10:18 -07:00
|
|
|
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_funcA;
|
2012-01-21 14:53:44 -07:00
|
|
|
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
|
|
|
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
|
|
|
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
|
|
|
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
|
|
|
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
|
|
|
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def)
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
|
2012-01-21 15:10:18 -07:00
|
|
|
pzlib_filefunc_def->zopendisk64_file = win32_opendisk64_file_funcW;
|
2012-01-21 14:53:44 -07:00
|
|
|
pzlib_filefunc_def->zread_file = win32_read_file_func;
|
|
|
|
pzlib_filefunc_def->zwrite_file = win32_write_file_func;
|
|
|
|
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
|
|
|
|
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
|
|
|
|
pzlib_filefunc_def->zclose_file = win32_close_file_func;
|
|
|
|
pzlib_filefunc_def->zerror_file = win32_error_file_func;
|
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|