20 #ifndef INVALID_HANDLE_VALUE 21 #define INVALID_HANDLE_VALUE (0xFFFFFFFF) 24 #ifndef INVALID_SET_FILE_POINTER 25 #define INVALID_SET_FILE_POINTER ((DWORD)-1) 29 #if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API))) 30 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) 31 #define IOWIN32_USING_WINRT_API 1 50 static void win32_translate_open_mode(
int mode,
51 DWORD* lpdwDesiredAccess,
52 DWORD* lpdwCreationDisposition,
54 DWORD* lpdwFlagsAndAttributes)
56 *lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0;
60 *lpdwDesiredAccess = GENERIC_READ;
61 *lpdwCreationDisposition = OPEN_EXISTING;
62 *lpdwShareMode = FILE_SHARE_READ;
66 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
67 *lpdwCreationDisposition = OPEN_EXISTING;
71 *lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
72 *lpdwCreationDisposition = CREATE_ALWAYS;
76 static voidpf win32_build_iowin(HANDLE hFile)
82 WIN32FILE_IOWIN w32fiow;
85 ret =
malloc(
sizeof(WIN32FILE_IOWIN));
90 *((WIN32FILE_IOWIN*)ret) = w32fiow;
97 const char* mode_fopen =
NULL;
98 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
101 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
103 #ifdef IOWIN32_USING_WINRT_API 105 if ((filename!=
NULL) && (dwDesiredAccess != 0))
106 hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
108 if ((filename!=
NULL) && (dwDesiredAccess != 0))
110 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
111 MultiByteToWideChar(CP_ACP,0,(
const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
112 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
116 if ((filename!=
NULL) && (dwDesiredAccess != 0))
117 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode,
NULL, dwCreationDisposition, dwFlagsAndAttributes,
NULL);
120 return win32_build_iowin(hFile);
126 const char* mode_fopen =
NULL;
127 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
130 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
132 #ifdef IOWIN32_USING_WINRT_API 133 if ((filename!=
NULL) && (dwDesiredAccess != 0))
135 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
136 MultiByteToWideChar(CP_ACP,0,(
const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
137 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
140 if ((filename!=
NULL) && (dwDesiredAccess != 0))
141 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode,
NULL, dwCreationDisposition, dwFlagsAndAttributes,
NULL);
144 return win32_build_iowin(hFile);
150 const char* mode_fopen =
NULL;
151 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
154 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
156 #ifdef IOWIN32_USING_WINRT_API 157 if ((filename!=
NULL) && (dwDesiredAccess != 0))
158 hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
160 if ((filename!=
NULL) && (dwDesiredAccess != 0))
161 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode,
NULL, dwCreationDisposition, dwFlagsAndAttributes,
NULL);
164 return win32_build_iowin(hFile);
170 const char* mode_fopen =
NULL;
171 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
174 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes);
176 #ifdef IOWIN32_USING_WINRT_API 178 if ((filename!=
NULL) && (dwDesiredAccess != 0))
179 hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
181 if ((filename!=
NULL) && (dwDesiredAccess != 0))
183 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
184 MultiByteToWideChar(CP_ACP,0,(
const char*)filename,-1,filenameW,FILENAME_MAX + 0x200);
185 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition,
NULL);
189 if ((filename!=
NULL) && (dwDesiredAccess != 0))
190 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode,
NULL, dwCreationDisposition, dwFlagsAndAttributes,
NULL);
193 return win32_build_iowin(hFile);
202 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
206 if (!ReadFile(hFile, buf, size, &ret,
NULL))
208 DWORD dwErr = GetLastError();
209 if (dwErr == ERROR_HANDLE_EOF)
211 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
224 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
228 if (!WriteFile(hFile, buf, size, &ret,
NULL))
230 DWORD dwErr = GetLastError();
231 if (dwErr == ERROR_HANDLE_EOF)
233 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
240 static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod)
242 #ifdef IOWIN32_USING_WINRT_API 243 return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
245 LONG lHigh = pos.HighPart;
246 DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, FILE_CURRENT);
248 if (dwNewPos == 0xFFFFFFFF)
249 if (GetLastError() != NO_ERROR)
251 if ((newPos !=
NULL) && (fOk))
253 newPos->LowPart = dwNewPos;
254 newPos->HighPart = lHigh;
265 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
271 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
273 DWORD dwErr = GetLastError();
274 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
278 ret=(
long)pos.LowPart;
288 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
295 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
297 DWORD dwErr = GetLastError();
298 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
310 DWORD dwMoveMethod=0xFFFFFFFF;
315 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
319 dwMoveMethod = FILE_CURRENT;
322 dwMoveMethod = FILE_END;
325 dwMoveMethod = FILE_BEGIN;
334 if (!MySetFilePointerEx(hFile, pos,
NULL, dwMoveMethod))
336 DWORD dwErr = GetLastError();
337 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
348 DWORD dwMoveMethod=0xFFFFFFFF;
353 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
358 dwMoveMethod = FILE_CURRENT;
361 dwMoveMethod = FILE_END;
364 dwMoveMethod = FILE_BEGIN;
373 if (!MySetFilePointerEx(hFile, pos,
NULL, FILE_CURRENT))
375 DWORD dwErr = GetLastError();
376 ((WIN32FILE_IOWIN*)stream) ->
error=(
int)dwErr;
392 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
408 ret = ((WIN32FILE_IOWIN*)stream) ->
error;
testerror_file_func zerror_file
testerror_file_func zerror_file
uLong ZCALLBACK win32_write_file_func(voidpf opaque, voidpf stream, const void *buf, uLong size)
void fill_win32_filefunc64W(zlib_filefunc64_def *pzlib_filefunc_def)
void fill_win32_filefunc64A(zlib_filefunc64_def *pzlib_filefunc_def)
write_file_func zwrite_file
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER
#define ZLIB_FILEFUNC_MODE_READ
void fill_win32_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
voidpf ZCALLBACK win32_open_file_func(voidpf opaque, const char *filename, int mode)
voidpf ZCALLBACK win32_open64_file_funcA(voidpf opaque, const void *filename, int mode)
GLenum GLuint GLenum GLsizei const GLchar * buf
#define INVALID_HANDLE_VALUE
write_file_func zwrite_file
#define ZLIB_FILEFUNC_SEEK_CUR
voidpf ZCALLBACK win32_open64_file_func(voidpf opaque, const void *filename, int mode)
int ZCALLBACK win32_close_file_func(voidpf opaque, voidpf stream)
close_file_func zclose_file
read_file_func zread_file
ZPOS64_T ZCALLBACK win32_tell64_file_func(voidpf opaque, voidpf stream)
seek_file_func zseek_file
long ZCALLBACK win32_tell_file_func(voidpf opaque, voidpf stream)
long ZCALLBACK win32_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin)
long ZCALLBACK win32_seek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque
int ZCALLBACK win32_error_file_func(voidpf opaque, voidpf stream)
#define ZLIB_FILEFUNC_MODE_CREATE
unsigned long long int ZPOS64_T
voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char *filename, int mode))
tell_file_func ztell_file
#define ZLIB_FILEFUNC_MODE_EXISTING
close_file_func zclose_file
voidpf ZCALLBACK win32_open64_file_funcW(voidpf opaque, const void *filename, int mode)
open_file_func zopen_file
read_file_func zread_file
void fill_win32_filefunc64(zlib_filefunc64_def *pzlib_filefunc_def)
open64_file_func zopen64_file
#define ZLIB_FILEFUNC_SEEK_END
seek64_file_func zseek64_file
uLong ZCALLBACK win32_read_file_func(voidpf opaque, voidpf stream, void *buf, uLong size)
#define ZLIB_FILEFUNC_SEEK_SET
tell64_file_func ztell64_file