2011-09-10 02:25:17 -04:00
|
|
|
/* iowin32.c -- IO base function header for compress/uncompress .zip
|
2011-09-10 02:27:26 -04:00
|
|
|
Version 1.1, February 14h, 2010
|
2011-09-10 02:26:49 -04:00
|
|
|
part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
|
2011-09-10 02:25:17 -04:00
|
|
|
|
2011-09-10 02:27:26 -04:00
|
|
|
Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
|
2011-09-10 02:26:49 -04:00
|
|
|
|
2011-09-10 02:27:26 -04:00
|
|
|
Modifications for Zip64 support
|
|
|
|
Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
|
2011-09-10 02:26:49 -04:00
|
|
|
|
|
|
|
For more info read MiniZip_info.txt
|
2011-09-10 02:25:17 -04:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
|
2013-08-03 21:13:23 -04:00
|
|
|
// see Include/shared/winapifamily.h in the Windows Kit
|
2013-04-14 13:05:43 -04:00
|
|
|
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
|
2013-08-03 21:13:23 -04:00
|
|
|
#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP)
|
2013-04-14 13:05:43 -04:00
|
|
|
#define IOWIN32_USING_WINRT_API 1
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-09-10 02:26:49 -04: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));
|
2011-09-10 02:25:17 -04:00
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
HANDLE hf;
|
|
|
|
int error;
|
|
|
|
} WIN32FILE_IOWIN;
|
|
|
|
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
static void win32_translate_open_mode(int mode,
|
|
|
|
DWORD* lpdwDesiredAccess,
|
|
|
|
DWORD* lpdwCreationDisposition,
|
|
|
|
DWORD* lpdwShareMode,
|
|
|
|
DWORD* lpdwFlagsAndAttributes)
|
|
|
|
{
|
|
|
|
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
|
2011-09-10 02:25:17 -04:00
|
|
|
|
|
|
|
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
|
|
|
|
{
|
2011-09-10 02:26:49 -04:00
|
|
|
*lpdwDesiredAccess = GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = OPEN_EXISTING;
|
|
|
|
*lpdwShareMode = FILE_SHARE_READ;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|
2011-09-10 02:26:49 -04:00
|
|
|
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
2011-09-10 02:26:49 -04:00
|
|
|
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = OPEN_EXISTING;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|
2011-09-10 02:26:49 -04:00
|
|
|
else if (mode & ZLIB_FILEFUNC_MODE_CREATE)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
2011-09-10 02:26:49 -04:00
|
|
|
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
|
|
|
|
*lpdwCreationDisposition = CREATE_ALWAYS;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|
2011-09-10 02:26:49 -04:00
|
|
|
}
|
2011-09-10 02:25:17 -04:00
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
static voidpf win32_build_iowin(HANDLE hFile)
|
|
|
|
{
|
|
|
|
voidpf ret=NULL;
|
2011-09-10 02:25:17 -04:00
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE))
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
WIN32FILE_IOWIN w32fiow;
|
|
|
|
w32fiow.hf = hFile;
|
|
|
|
w32fiow.error = 0;
|
|
|
|
ret = malloc(sizeof(WIN32FILE_IOWIN));
|
2011-09-10 02:26:49 -04:00
|
|
|
|
2011-09-10 02:25:17 -04:00
|
|
|
if (ret==NULL)
|
|
|
|
CloseHandle(hFile);
|
2011-09-10 02:26:49 -04:00
|
|
|
else
|
|
|
|
*((WIN32FILE_IOWIN*)ret) = w32fiow;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
|
|
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
|
|
|
|
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
#ifdef UNICODE
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
{
|
|
|
|
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
|
2011-09-10 02:26:49 -04:00
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2013-04-14 13:05:43 -04:00
|
|
|
#endif
|
2011-09-10 02:26:49 -04:00
|
|
|
|
|
|
|
return win32_build_iowin(hFile);
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:25:17 -04:00
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
|
|
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
|
|
|
|
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
{
|
|
|
|
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
|
2011-09-10 02:26:49 -04:00
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2013-04-14 13:05:43 -04:00
|
|
|
#endif
|
2011-09-10 02:26:49 -04:00
|
|
|
|
|
|
|
return win32_build_iowin(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
|
|
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
|
|
|
|
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL);
|
|
|
|
#else
|
2011-09-10 02:26:49 -04:00
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2013-04-14 13:05:43 -04:00
|
|
|
#endif
|
2011-09-10 02:26:49 -04:00
|
|
|
|
|
|
|
return win32_build_iowin(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mode)
|
|
|
|
{
|
|
|
|
const char* mode_fopen = NULL;
|
|
|
|
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
|
|
|
|
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
#ifdef IOWIN32_USING_WINRT_API
|
|
|
|
#ifdef UNICODE
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL);
|
|
|
|
#else
|
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
{
|
|
|
|
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
|
2011-09-10 02:26:49 -04:00
|
|
|
if ((filename!=NULL) && (dwDesiredAccess != 0))
|
|
|
|
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL);
|
2013-04-14 13:05:43 -04:00
|
|
|
#endif
|
2011-09-10 02:26:49 -04:00
|
|
|
|
|
|
|
return win32_build_iowin(hFile);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uLong size)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
uLong ret=0;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
2011-09-10 02:26:49 -04:00
|
|
|
|
2011-09-10 02:25:17 -04:00
|
|
|
if (hFile != NULL)
|
2011-09-10 02:26:49 -04:00
|
|
|
{
|
2011-09-10 02:25:17 -04:00
|
|
|
if (!ReadFile(hFile, buf, size, &ret, NULL))
|
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
if (dwErr == ERROR_HANDLE_EOF)
|
|
|
|
dwErr = 0;
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
}
|
2011-09-10 02:26:49 -04:00
|
|
|
}
|
2011-09-10 02:25:17 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* buf,uLong size)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
uLong ret=0;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
2011-09-10 02:25:17 -04:00
|
|
|
if (!WriteFile(hFile, buf, size, &ret, NULL))
|
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
if (dwErr == ERROR_HANDLE_EOF)
|
|
|
|
dwErr = 0;
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
}
|
2011-09-10 02:26:49 -04:00
|
|
|
}
|
2011-09-10 02:25:17 -04:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-04-14 13:05:43 -04:00
|
|
|
static BOOL MySetFilePointerEx(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;
|
2013-08-03 21:13:23 -04:00
|
|
|
DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
|
2013-04-14 13:05:43 -04:00
|
|
|
BOOL fOk = TRUE;
|
|
|
|
if (dwNewPos == 0xFFFFFFFF)
|
|
|
|
if (GetLastError() != NO_ERROR)
|
|
|
|
fOk = FALSE;
|
|
|
|
if ((newPos != NULL) && (fOk))
|
|
|
|
{
|
|
|
|
newPos->LowPart = dwNewPos;
|
|
|
|
newPos->HighPart = lHigh;
|
|
|
|
}
|
|
|
|
return fOk;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
long ret=-1;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
2013-04-14 13:05:43 -04:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
|
|
|
|
if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
2013-04-14 13:05:43 -04:00
|
|
|
ret=(long)pos.LowPart;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
|
|
|
|
{
|
|
|
|
ZPOS64_T ret= (ZPOS64_T)-1;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
|
|
|
|
|
|
|
if (hFile)
|
|
|
|
{
|
2013-04-14 13:05:43 -04:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = 0;
|
|
|
|
|
|
|
|
if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
|
2011-09-10 02:26:49 -04:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
ret = (ZPOS64_T)-1;
|
|
|
|
}
|
|
|
|
else
|
2013-04-14 13:05:43 -04:00
|
|
|
ret=pos.QuadPart;
|
2011-09-10 02:26:49 -04:00
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,int origin)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
DWORD dwMoveMethod=0xFFFFFFFF;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
|
|
|
|
long ret=-1;
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
|
|
|
switch (origin)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
2013-04-14 13:05:43 -04:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = offset;
|
|
|
|
if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret=0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T offset,int origin)
|
|
|
|
{
|
|
|
|
DWORD dwMoveMethod=0xFFFFFFFF;
|
|
|
|
HANDLE hFile = NULL;
|
|
|
|
long ret=-1;
|
|
|
|
|
|
|
|
if (stream!=NULL)
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream)->hf;
|
|
|
|
|
|
|
|
switch (origin)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hFile)
|
|
|
|
{
|
2013-04-14 13:05:43 -04:00
|
|
|
LARGE_INTEGER pos;
|
|
|
|
pos.QuadPart = offset;
|
2013-08-03 21:13:23 -04:00
|
|
|
if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
|
2011-09-10 02:26:49 -04:00
|
|
|
{
|
|
|
|
DWORD dwErr = GetLastError();
|
|
|
|
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
|
|
|
|
ret = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
ret=0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ZCALLBACK win32_close_file_func (voidpf opaque, voidpf stream)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
int ret=-1;
|
|
|
|
|
|
|
|
if (stream!=NULL)
|
|
|
|
{
|
|
|
|
HANDLE hFile;
|
|
|
|
hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
|
|
|
|
if (hFile != NULL)
|
|
|
|
{
|
|
|
|
CloseHandle(hFile);
|
|
|
|
ret=0;
|
|
|
|
}
|
|
|
|
free(stream);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
int ZCALLBACK win32_error_file_func (voidpf opaque,voidpf stream)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
int ret=-1;
|
|
|
|
if (stream!=NULL)
|
|
|
|
{
|
|
|
|
ret = ((WIN32FILE_IOWIN*)stream) -> error;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-09-10 02:26:49 -04:00
|
|
|
void fill_win32_filefunc (zlib_filefunc_def* pzlib_filefunc_def)
|
2011-09-10 02:25:17 -04:00
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen_file = win32_open_file_func;
|
|
|
|
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;
|
2011-09-10 02:26:49 -04:00
|
|
|
pzlib_filefunc_def->opaque = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def)
|
|
|
|
{
|
|
|
|
pzlib_filefunc_def->zopen64_file = win32_open64_file_func;
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
2011-09-10 02:25:17 -04:00
|
|
|
}
|