|
7ef7284…
|
drh
|
1 |
/* iowin32.c -- IO base function header for compress/uncompress .zip |
|
6ea30fb…
|
florian
|
2 |
part of the MiniZip project - ( https://www.winimage.com/zLibDll/minizip.html ) |
|
7ef7284…
|
drh
|
3 |
|
|
6ea30fb…
|
florian
|
4 |
Copyright (C) 1998-2026 Gilles Vollant (minizip) ( https://www.winimage.com/zLibDll/minizip.html ) |
|
7ef7284…
|
drh
|
5 |
|
|
7ef7284…
|
drh
|
6 |
Modifications for Zip64 support |
|
6ea30fb…
|
florian
|
7 |
Copyright (C) 2009-2010 Mathias Svensson ( https://result42.com ) |
|
7ef7284…
|
drh
|
8 |
|
|
7ef7284…
|
drh
|
9 |
For more info read MiniZip_info.txt |
|
7ef7284…
|
drh
|
10 |
|
|
7ef7284…
|
drh
|
11 |
*/ |
|
7ef7284…
|
drh
|
12 |
|
|
7ef7284…
|
drh
|
13 |
#include <stdlib.h> |
|
7ef7284…
|
drh
|
14 |
|
|
7ef7284…
|
drh
|
15 |
#include "zlib.h" |
|
7ef7284…
|
drh
|
16 |
#include "ioapi.h" |
|
7ef7284…
|
drh
|
17 |
#include "iowin32.h" |
|
7ef7284…
|
drh
|
18 |
|
|
7ef7284…
|
drh
|
19 |
#ifndef INVALID_HANDLE_VALUE |
|
7ef7284…
|
drh
|
20 |
#define INVALID_HANDLE_VALUE (0xFFFFFFFF) |
|
7ef7284…
|
drh
|
21 |
#endif |
|
7ef7284…
|
drh
|
22 |
|
|
7ef7284…
|
drh
|
23 |
#ifndef INVALID_SET_FILE_POINTER |
|
7ef7284…
|
drh
|
24 |
#define INVALID_SET_FILE_POINTER ((DWORD)-1) |
|
7ef7284…
|
drh
|
25 |
#endif |
|
7ef7284…
|
drh
|
26 |
|
|
bb4776e…
|
jan.nijtmans
|
27 |
|
|
6ea30fb…
|
florian
|
28 |
/* see Include/shared/winapifamily.h in the Windows Kit */ |
|
bb4776e…
|
jan.nijtmans
|
29 |
#if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API))) |
|
a9e589c…
|
florian
|
30 |
|
|
a9e589c…
|
florian
|
31 |
#if !defined(WINAPI_FAMILY_ONE_PARTITION) |
|
a9e589c…
|
florian
|
32 |
#define WINAPI_FAMILY_ONE_PARTITION(PartitionSet, Partition) ((WINAPI_FAMILY & PartitionSet) == Partition) |
|
a9e589c…
|
florian
|
33 |
#endif |
|
a9e589c…
|
florian
|
34 |
|
|
e38d5e1…
|
jan.nijtmans
|
35 |
#if WINAPI_FAMILY_ONE_PARTITION(WINAPI_FAMILY, WINAPI_PARTITION_APP) |
|
bb4776e…
|
jan.nijtmans
|
36 |
#define IOWIN32_USING_WINRT_API 1 |
|
bb4776e…
|
jan.nijtmans
|
37 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
38 |
#endif |
|
7ef7284…
|
drh
|
39 |
|
|
7ef7284…
|
drh
|
40 |
typedef struct |
|
7ef7284…
|
drh
|
41 |
{ |
|
7ef7284…
|
drh
|
42 |
HANDLE hf; |
|
7ef7284…
|
drh
|
43 |
int error; |
|
7ef7284…
|
drh
|
44 |
} WIN32FILE_IOWIN; |
|
7ef7284…
|
drh
|
45 |
|
|
7ef7284…
|
drh
|
46 |
|
|
7ef7284…
|
drh
|
47 |
static void win32_translate_open_mode(int mode, |
|
7ef7284…
|
drh
|
48 |
DWORD* lpdwDesiredAccess, |
|
7ef7284…
|
drh
|
49 |
DWORD* lpdwCreationDisposition, |
|
7ef7284…
|
drh
|
50 |
DWORD* lpdwShareMode, |
|
f1f1d6c…
|
drh
|
51 |
DWORD* lpdwFlagsAndAttributes) { |
|
7ef7284…
|
drh
|
52 |
*lpdwDesiredAccess = *lpdwShareMode = *lpdwFlagsAndAttributes = *lpdwCreationDisposition = 0; |
|
7ef7284…
|
drh
|
53 |
|
|
7ef7284…
|
drh
|
54 |
if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
|
7ef7284…
|
drh
|
55 |
{ |
|
7ef7284…
|
drh
|
56 |
*lpdwDesiredAccess = GENERIC_READ; |
|
7ef7284…
|
drh
|
57 |
*lpdwCreationDisposition = OPEN_EXISTING; |
|
7ef7284…
|
drh
|
58 |
*lpdwShareMode = FILE_SHARE_READ; |
|
7ef7284…
|
drh
|
59 |
} |
|
7ef7284…
|
drh
|
60 |
else if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
|
7ef7284…
|
drh
|
61 |
{ |
|
7ef7284…
|
drh
|
62 |
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
|
7ef7284…
|
drh
|
63 |
*lpdwCreationDisposition = OPEN_EXISTING; |
|
7ef7284…
|
drh
|
64 |
} |
|
7ef7284…
|
drh
|
65 |
else if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
|
7ef7284…
|
drh
|
66 |
{ |
|
7ef7284…
|
drh
|
67 |
*lpdwDesiredAccess = GENERIC_WRITE | GENERIC_READ; |
|
7ef7284…
|
drh
|
68 |
*lpdwCreationDisposition = CREATE_ALWAYS; |
|
7ef7284…
|
drh
|
69 |
} |
|
7ef7284…
|
drh
|
70 |
} |
|
7ef7284…
|
drh
|
71 |
|
|
f1f1d6c…
|
drh
|
72 |
static voidpf win32_build_iowin(HANDLE hFile) { |
|
7ef7284…
|
drh
|
73 |
voidpf ret=NULL; |
|
7ef7284…
|
drh
|
74 |
|
|
7ef7284…
|
drh
|
75 |
if ((hFile != NULL) && (hFile != INVALID_HANDLE_VALUE)) |
|
7ef7284…
|
drh
|
76 |
{ |
|
7ef7284…
|
drh
|
77 |
WIN32FILE_IOWIN w32fiow; |
|
7ef7284…
|
drh
|
78 |
w32fiow.hf = hFile; |
|
7ef7284…
|
drh
|
79 |
w32fiow.error = 0; |
|
7ef7284…
|
drh
|
80 |
ret = malloc(sizeof(WIN32FILE_IOWIN)); |
|
7ef7284…
|
drh
|
81 |
|
|
7ef7284…
|
drh
|
82 |
if (ret==NULL) |
|
7ef7284…
|
drh
|
83 |
CloseHandle(hFile); |
|
7ef7284…
|
drh
|
84 |
else |
|
7ef7284…
|
drh
|
85 |
*((WIN32FILE_IOWIN*)ret) = w32fiow; |
|
7ef7284…
|
drh
|
86 |
} |
|
7ef7284…
|
drh
|
87 |
return ret; |
|
7ef7284…
|
drh
|
88 |
} |
|
7ef7284…
|
drh
|
89 |
|
|
f1f1d6c…
|
drh
|
90 |
voidpf ZCALLBACK win32_open64_file_func(voidpf opaque, const void* filename, int mode) { |
|
6ea30fb…
|
florian
|
91 |
(void)opaque; |
|
bb4776e…
|
jan.nijtmans
|
92 |
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
|
bb4776e…
|
jan.nijtmans
|
93 |
HANDLE hFile = NULL; |
|
bb4776e…
|
jan.nijtmans
|
94 |
|
|
bb4776e…
|
jan.nijtmans
|
95 |
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); |
|
bb4776e…
|
jan.nijtmans
|
96 |
|
|
bb4776e…
|
jan.nijtmans
|
97 |
#ifdef IOWIN32_USING_WINRT_API |
|
bb4776e…
|
jan.nijtmans
|
98 |
#ifdef UNICODE |
|
bb4776e…
|
jan.nijtmans
|
99 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
100 |
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); |
|
bb4776e…
|
jan.nijtmans
|
101 |
#else |
|
bb4776e…
|
jan.nijtmans
|
102 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
103 |
{ |
|
bb4776e…
|
jan.nijtmans
|
104 |
WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; |
|
bb4776e…
|
jan.nijtmans
|
105 |
MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); |
|
bb4776e…
|
jan.nijtmans
|
106 |
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); |
|
bb4776e…
|
jan.nijtmans
|
107 |
} |
|
bb4776e…
|
jan.nijtmans
|
108 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
109 |
#else |
|
bb4776e…
|
jan.nijtmans
|
110 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
111 |
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); |
|
bb4776e…
|
jan.nijtmans
|
112 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
113 |
|
|
bb4776e…
|
jan.nijtmans
|
114 |
return win32_build_iowin(hFile); |
|
bb4776e…
|
jan.nijtmans
|
115 |
} |
|
bb4776e…
|
jan.nijtmans
|
116 |
|
|
bb4776e…
|
jan.nijtmans
|
117 |
|
|
f1f1d6c…
|
drh
|
118 |
voidpf ZCALLBACK win32_open64_file_funcA(voidpf opaque, const void* filename, int mode) { |
|
6ea30fb…
|
florian
|
119 |
(void)opaque; |
|
bb4776e…
|
jan.nijtmans
|
120 |
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
|
bb4776e…
|
jan.nijtmans
|
121 |
HANDLE hFile = NULL; |
|
bb4776e…
|
jan.nijtmans
|
122 |
|
|
bb4776e…
|
jan.nijtmans
|
123 |
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); |
|
bb4776e…
|
jan.nijtmans
|
124 |
|
|
bb4776e…
|
jan.nijtmans
|
125 |
#ifdef IOWIN32_USING_WINRT_API |
|
bb4776e…
|
jan.nijtmans
|
126 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
127 |
{ |
|
bb4776e…
|
jan.nijtmans
|
128 |
WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; |
|
bb4776e…
|
jan.nijtmans
|
129 |
MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); |
|
bb4776e…
|
jan.nijtmans
|
130 |
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); |
|
bb4776e…
|
jan.nijtmans
|
131 |
} |
|
bb4776e…
|
jan.nijtmans
|
132 |
#else |
|
bb4776e…
|
jan.nijtmans
|
133 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
134 |
hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); |
|
bb4776e…
|
jan.nijtmans
|
135 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
136 |
|
|
bb4776e…
|
jan.nijtmans
|
137 |
return win32_build_iowin(hFile); |
|
bb4776e…
|
jan.nijtmans
|
138 |
} |
|
bb4776e…
|
jan.nijtmans
|
139 |
|
|
bb4776e…
|
jan.nijtmans
|
140 |
|
|
f1f1d6c…
|
drh
|
141 |
voidpf ZCALLBACK win32_open64_file_funcW(voidpf opaque, const void* filename, int mode) { |
|
6ea30fb…
|
florian
|
142 |
(void)opaque; |
|
bb4776e…
|
jan.nijtmans
|
143 |
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
|
bb4776e…
|
jan.nijtmans
|
144 |
HANDLE hFile = NULL; |
|
bb4776e…
|
jan.nijtmans
|
145 |
|
|
bb4776e…
|
jan.nijtmans
|
146 |
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); |
|
bb4776e…
|
jan.nijtmans
|
147 |
|
|
bb4776e…
|
jan.nijtmans
|
148 |
#ifdef IOWIN32_USING_WINRT_API |
|
bb4776e…
|
jan.nijtmans
|
149 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
150 |
hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL); |
|
bb4776e…
|
jan.nijtmans
|
151 |
#else |
|
bb4776e…
|
jan.nijtmans
|
152 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
153 |
hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); |
|
bb4776e…
|
jan.nijtmans
|
154 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
155 |
|
|
bb4776e…
|
jan.nijtmans
|
156 |
return win32_build_iowin(hFile); |
|
bb4776e…
|
jan.nijtmans
|
157 |
} |
|
bb4776e…
|
jan.nijtmans
|
158 |
|
|
bb4776e…
|
jan.nijtmans
|
159 |
|
|
f1f1d6c…
|
drh
|
160 |
voidpf ZCALLBACK win32_open_file_func(voidpf opaque, const char* filename, int mode) { |
|
6ea30fb…
|
florian
|
161 |
(void)opaque; |
|
bb4776e…
|
jan.nijtmans
|
162 |
DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; |
|
bb4776e…
|
jan.nijtmans
|
163 |
HANDLE hFile = NULL; |
|
bb4776e…
|
jan.nijtmans
|
164 |
|
|
bb4776e…
|
jan.nijtmans
|
165 |
win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); |
|
bb4776e…
|
jan.nijtmans
|
166 |
|
|
bb4776e…
|
jan.nijtmans
|
167 |
#ifdef IOWIN32_USING_WINRT_API |
|
bb4776e…
|
jan.nijtmans
|
168 |
#ifdef UNICODE |
|
bb4776e…
|
jan.nijtmans
|
169 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
170 |
hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); |
|
bb4776e…
|
jan.nijtmans
|
171 |
#else |
|
bb4776e…
|
jan.nijtmans
|
172 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
173 |
{ |
|
bb4776e…
|
jan.nijtmans
|
174 |
WCHAR filenameW[FILENAME_MAX + 0x200 + 1]; |
|
bb4776e…
|
jan.nijtmans
|
175 |
MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME_MAX + 0x200); |
|
bb4776e…
|
jan.nijtmans
|
176 |
hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationDisposition, NULL); |
|
bb4776e…
|
jan.nijtmans
|
177 |
} |
|
bb4776e…
|
jan.nijtmans
|
178 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
179 |
#else |
|
bb4776e…
|
jan.nijtmans
|
180 |
if ((filename!=NULL) && (dwDesiredAccess != 0)) |
|
bb4776e…
|
jan.nijtmans
|
181 |
hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); |
|
bb4776e…
|
jan.nijtmans
|
182 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
183 |
|
|
bb4776e…
|
jan.nijtmans
|
184 |
return win32_build_iowin(hFile); |
|
bb4776e…
|
jan.nijtmans
|
185 |
} |
|
bb4776e…
|
jan.nijtmans
|
186 |
|
|
bb4776e…
|
jan.nijtmans
|
187 |
|
|
f1f1d6c…
|
drh
|
188 |
uLong ZCALLBACK win32_read_file_func(voidpf opaque, voidpf stream, void* buf,uLong size) { |
|
6ea30fb…
|
florian
|
189 |
(void)opaque; |
|
7ef7284…
|
drh
|
190 |
uLong ret=0; |
|
7ef7284…
|
drh
|
191 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
192 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
193 |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
|
7ef7284…
|
drh
|
194 |
|
|
7ef7284…
|
drh
|
195 |
if (hFile != NULL) |
|
7ef7284…
|
drh
|
196 |
{ |
|
7ef7284…
|
drh
|
197 |
if (!ReadFile(hFile, buf, size, &ret, NULL)) |
|
7ef7284…
|
drh
|
198 |
{ |
|
7ef7284…
|
drh
|
199 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
200 |
if (dwErr == ERROR_HANDLE_EOF) |
|
7ef7284…
|
drh
|
201 |
dwErr = 0; |
|
7ef7284…
|
drh
|
202 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
203 |
} |
|
7ef7284…
|
drh
|
204 |
} |
|
7ef7284…
|
drh
|
205 |
|
|
7ef7284…
|
drh
|
206 |
return ret; |
|
7ef7284…
|
drh
|
207 |
} |
|
7ef7284…
|
drh
|
208 |
|
|
7ef7284…
|
drh
|
209 |
|
|
f1f1d6c…
|
drh
|
210 |
uLong ZCALLBACK win32_write_file_func(voidpf opaque, voidpf stream, const void* buf, uLong size) { |
|
6ea30fb…
|
florian
|
211 |
(void)opaque; |
|
7ef7284…
|
drh
|
212 |
uLong ret=0; |
|
7ef7284…
|
drh
|
213 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
214 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
215 |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
|
7ef7284…
|
drh
|
216 |
|
|
7ef7284…
|
drh
|
217 |
if (hFile != NULL) |
|
7ef7284…
|
drh
|
218 |
{ |
|
7ef7284…
|
drh
|
219 |
if (!WriteFile(hFile, buf, size, &ret, NULL)) |
|
7ef7284…
|
drh
|
220 |
{ |
|
7ef7284…
|
drh
|
221 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
222 |
if (dwErr == ERROR_HANDLE_EOF) |
|
7ef7284…
|
drh
|
223 |
dwErr = 0; |
|
7ef7284…
|
drh
|
224 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
225 |
} |
|
7ef7284…
|
drh
|
226 |
} |
|
7ef7284…
|
drh
|
227 |
|
|
7ef7284…
|
drh
|
228 |
return ret; |
|
7ef7284…
|
drh
|
229 |
} |
|
7ef7284…
|
drh
|
230 |
|
|
f1f1d6c…
|
drh
|
231 |
static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, DWORD dwMoveMethod) { |
|
bb4776e…
|
jan.nijtmans
|
232 |
#ifdef IOWIN32_USING_WINRT_API |
|
bb4776e…
|
jan.nijtmans
|
233 |
return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod); |
|
bb4776e…
|
jan.nijtmans
|
234 |
#else |
|
bb4776e…
|
jan.nijtmans
|
235 |
LONG lHigh = pos.HighPart; |
|
e38d5e1…
|
jan.nijtmans
|
236 |
DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod); |
|
bb4776e…
|
jan.nijtmans
|
237 |
BOOL fOk = TRUE; |
|
bb4776e…
|
jan.nijtmans
|
238 |
if (dwNewPos == 0xFFFFFFFF) |
|
bb4776e…
|
jan.nijtmans
|
239 |
if (GetLastError() != NO_ERROR) |
|
bb4776e…
|
jan.nijtmans
|
240 |
fOk = FALSE; |
|
bb4776e…
|
jan.nijtmans
|
241 |
if ((newPos != NULL) && (fOk)) |
|
bb4776e…
|
jan.nijtmans
|
242 |
{ |
|
bb4776e…
|
jan.nijtmans
|
243 |
newPos->LowPart = dwNewPos; |
|
bb4776e…
|
jan.nijtmans
|
244 |
newPos->HighPart = lHigh; |
|
bb4776e…
|
jan.nijtmans
|
245 |
} |
|
bb4776e…
|
jan.nijtmans
|
246 |
return fOk; |
|
bb4776e…
|
jan.nijtmans
|
247 |
#endif |
|
bb4776e…
|
jan.nijtmans
|
248 |
} |
|
bb4776e…
|
jan.nijtmans
|
249 |
|
|
f1f1d6c…
|
drh
|
250 |
long ZCALLBACK win32_tell_file_func(voidpf opaque, voidpf stream) { |
|
6ea30fb…
|
florian
|
251 |
(void)opaque; |
|
7ef7284…
|
drh
|
252 |
long ret=-1; |
|
7ef7284…
|
drh
|
253 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
254 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
255 |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
|
7ef7284…
|
drh
|
256 |
if (hFile != NULL) |
|
7ef7284…
|
drh
|
257 |
{ |
|
bb4776e…
|
jan.nijtmans
|
258 |
LARGE_INTEGER pos; |
|
bb4776e…
|
jan.nijtmans
|
259 |
pos.QuadPart = 0; |
|
bb4776e…
|
jan.nijtmans
|
260 |
|
|
bb4776e…
|
jan.nijtmans
|
261 |
if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT)) |
|
7ef7284…
|
drh
|
262 |
{ |
|
7ef7284…
|
drh
|
263 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
264 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
265 |
ret = -1; |
|
7ef7284…
|
drh
|
266 |
} |
|
7ef7284…
|
drh
|
267 |
else |
|
bb4776e…
|
jan.nijtmans
|
268 |
ret=(long)pos.LowPart; |
|
7ef7284…
|
drh
|
269 |
} |
|
7ef7284…
|
drh
|
270 |
return ret; |
|
7ef7284…
|
drh
|
271 |
} |
|
7ef7284…
|
drh
|
272 |
|
|
f1f1d6c…
|
drh
|
273 |
ZPOS64_T ZCALLBACK win32_tell64_file_func(voidpf opaque, voidpf stream) { |
|
6ea30fb…
|
florian
|
274 |
(void)opaque; |
|
7ef7284…
|
drh
|
275 |
ZPOS64_T ret= (ZPOS64_T)-1; |
|
7ef7284…
|
drh
|
276 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
277 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
278 |
hFile = ((WIN32FILE_IOWIN*)stream)->hf; |
|
7ef7284…
|
drh
|
279 |
|
|
7ef7284…
|
drh
|
280 |
if (hFile) |
|
7ef7284…
|
drh
|
281 |
{ |
|
bb4776e…
|
jan.nijtmans
|
282 |
LARGE_INTEGER pos; |
|
bb4776e…
|
jan.nijtmans
|
283 |
pos.QuadPart = 0; |
|
bb4776e…
|
jan.nijtmans
|
284 |
|
|
bb4776e…
|
jan.nijtmans
|
285 |
if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT)) |
|
7ef7284…
|
drh
|
286 |
{ |
|
7ef7284…
|
drh
|
287 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
288 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
289 |
ret = (ZPOS64_T)-1; |
|
7ef7284…
|
drh
|
290 |
} |
|
7ef7284…
|
drh
|
291 |
else |
|
bb4776e…
|
jan.nijtmans
|
292 |
ret=pos.QuadPart; |
|
7ef7284…
|
drh
|
293 |
} |
|
7ef7284…
|
drh
|
294 |
return ret; |
|
7ef7284…
|
drh
|
295 |
} |
|
7ef7284…
|
drh
|
296 |
|
|
7ef7284…
|
drh
|
297 |
|
|
f1f1d6c…
|
drh
|
298 |
long ZCALLBACK win32_seek_file_func(voidpf opaque, voidpf stream, uLong offset, int origin) { |
|
6ea30fb…
|
florian
|
299 |
(void)opaque; |
|
7ef7284…
|
drh
|
300 |
DWORD dwMoveMethod=0xFFFFFFFF; |
|
7ef7284…
|
drh
|
301 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
302 |
|
|
7ef7284…
|
drh
|
303 |
long ret=-1; |
|
7ef7284…
|
drh
|
304 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
305 |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
|
7ef7284…
|
drh
|
306 |
switch (origin) |
|
7ef7284…
|
drh
|
307 |
{ |
|
7ef7284…
|
drh
|
308 |
case ZLIB_FILEFUNC_SEEK_CUR : |
|
7ef7284…
|
drh
|
309 |
dwMoveMethod = FILE_CURRENT; |
|
7ef7284…
|
drh
|
310 |
break; |
|
7ef7284…
|
drh
|
311 |
case ZLIB_FILEFUNC_SEEK_END : |
|
7ef7284…
|
drh
|
312 |
dwMoveMethod = FILE_END; |
|
7ef7284…
|
drh
|
313 |
break; |
|
7ef7284…
|
drh
|
314 |
case ZLIB_FILEFUNC_SEEK_SET : |
|
7ef7284…
|
drh
|
315 |
dwMoveMethod = FILE_BEGIN; |
|
7ef7284…
|
drh
|
316 |
break; |
|
7ef7284…
|
drh
|
317 |
default: return -1; |
|
7ef7284…
|
drh
|
318 |
} |
|
7ef7284…
|
drh
|
319 |
|
|
7ef7284…
|
drh
|
320 |
if (hFile != NULL) |
|
7ef7284…
|
drh
|
321 |
{ |
|
bb4776e…
|
jan.nijtmans
|
322 |
LARGE_INTEGER pos; |
|
bb4776e…
|
jan.nijtmans
|
323 |
pos.QuadPart = offset; |
|
bb4776e…
|
jan.nijtmans
|
324 |
if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod)) |
|
7ef7284…
|
drh
|
325 |
{ |
|
7ef7284…
|
drh
|
326 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
327 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
328 |
ret = -1; |
|
7ef7284…
|
drh
|
329 |
} |
|
7ef7284…
|
drh
|
330 |
else |
|
7ef7284…
|
drh
|
331 |
ret=0; |
|
7ef7284…
|
drh
|
332 |
} |
|
7ef7284…
|
drh
|
333 |
return ret; |
|
7ef7284…
|
drh
|
334 |
} |
|
7ef7284…
|
drh
|
335 |
|
|
f1f1d6c…
|
drh
|
336 |
long ZCALLBACK win32_seek64_file_func(voidpf opaque, voidpf stream, ZPOS64_T offset, int origin) { |
|
6ea30fb…
|
florian
|
337 |
(void)opaque; |
|
7ef7284…
|
drh
|
338 |
DWORD dwMoveMethod=0xFFFFFFFF; |
|
7ef7284…
|
drh
|
339 |
HANDLE hFile = NULL; |
|
7ef7284…
|
drh
|
340 |
long ret=-1; |
|
7ef7284…
|
drh
|
341 |
|
|
7ef7284…
|
drh
|
342 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
343 |
hFile = ((WIN32FILE_IOWIN*)stream)->hf; |
|
7ef7284…
|
drh
|
344 |
|
|
7ef7284…
|
drh
|
345 |
switch (origin) |
|
7ef7284…
|
drh
|
346 |
{ |
|
7ef7284…
|
drh
|
347 |
case ZLIB_FILEFUNC_SEEK_CUR : |
|
7ef7284…
|
drh
|
348 |
dwMoveMethod = FILE_CURRENT; |
|
7ef7284…
|
drh
|
349 |
break; |
|
7ef7284…
|
drh
|
350 |
case ZLIB_FILEFUNC_SEEK_END : |
|
7ef7284…
|
drh
|
351 |
dwMoveMethod = FILE_END; |
|
7ef7284…
|
drh
|
352 |
break; |
|
7ef7284…
|
drh
|
353 |
case ZLIB_FILEFUNC_SEEK_SET : |
|
7ef7284…
|
drh
|
354 |
dwMoveMethod = FILE_BEGIN; |
|
7ef7284…
|
drh
|
355 |
break; |
|
7ef7284…
|
drh
|
356 |
default: return -1; |
|
7ef7284…
|
drh
|
357 |
} |
|
7ef7284…
|
drh
|
358 |
|
|
7ef7284…
|
drh
|
359 |
if (hFile) |
|
7ef7284…
|
drh
|
360 |
{ |
|
bb4776e…
|
jan.nijtmans
|
361 |
LARGE_INTEGER pos; |
|
bb4776e…
|
jan.nijtmans
|
362 |
pos.QuadPart = offset; |
|
e38d5e1…
|
jan.nijtmans
|
363 |
if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod)) |
|
7ef7284…
|
drh
|
364 |
{ |
|
7ef7284…
|
drh
|
365 |
DWORD dwErr = GetLastError(); |
|
7ef7284…
|
drh
|
366 |
((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; |
|
7ef7284…
|
drh
|
367 |
ret = -1; |
|
7ef7284…
|
drh
|
368 |
} |
|
7ef7284…
|
drh
|
369 |
else |
|
7ef7284…
|
drh
|
370 |
ret=0; |
|
7ef7284…
|
drh
|
371 |
} |
|
7ef7284…
|
drh
|
372 |
return ret; |
|
7ef7284…
|
drh
|
373 |
} |
|
7ef7284…
|
drh
|
374 |
|
|
f1f1d6c…
|
drh
|
375 |
int ZCALLBACK win32_close_file_func(voidpf opaque, voidpf stream) { |
|
6ea30fb…
|
florian
|
376 |
(void)opaque; |
|
7ef7284…
|
drh
|
377 |
int ret=-1; |
|
7ef7284…
|
drh
|
378 |
|
|
7ef7284…
|
drh
|
379 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
380 |
{ |
|
7ef7284…
|
drh
|
381 |
HANDLE hFile; |
|
7ef7284…
|
drh
|
382 |
hFile = ((WIN32FILE_IOWIN*)stream) -> hf; |
|
7ef7284…
|
drh
|
383 |
if (hFile != NULL) |
|
7ef7284…
|
drh
|
384 |
{ |
|
7ef7284…
|
drh
|
385 |
CloseHandle(hFile); |
|
7ef7284…
|
drh
|
386 |
ret=0; |
|
7ef7284…
|
drh
|
387 |
} |
|
7ef7284…
|
drh
|
388 |
free(stream); |
|
7ef7284…
|
drh
|
389 |
} |
|
7ef7284…
|
drh
|
390 |
return ret; |
|
7ef7284…
|
drh
|
391 |
} |
|
7ef7284…
|
drh
|
392 |
|
|
f1f1d6c…
|
drh
|
393 |
int ZCALLBACK win32_error_file_func(voidpf opaque, voidpf stream) { |
|
6ea30fb…
|
florian
|
394 |
(void)opaque; |
|
7ef7284…
|
drh
|
395 |
int ret=-1; |
|
7ef7284…
|
drh
|
396 |
if (stream!=NULL) |
|
7ef7284…
|
drh
|
397 |
{ |
|
7ef7284…
|
drh
|
398 |
ret = ((WIN32FILE_IOWIN*)stream) -> error; |
|
7ef7284…
|
drh
|
399 |
} |
|
7ef7284…
|
drh
|
400 |
return ret; |
|
7ef7284…
|
drh
|
401 |
} |
|
7ef7284…
|
drh
|
402 |
|
|
f1f1d6c…
|
drh
|
403 |
void fill_win32_filefunc(zlib_filefunc_def* pzlib_filefunc_def) { |
|
7ef7284…
|
drh
|
404 |
pzlib_filefunc_def->zopen_file = win32_open_file_func; |
|
7ef7284…
|
drh
|
405 |
pzlib_filefunc_def->zread_file = win32_read_file_func; |
|
7ef7284…
|
drh
|
406 |
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
|
7ef7284…
|
drh
|
407 |
pzlib_filefunc_def->ztell_file = win32_tell_file_func; |
|
7ef7284…
|
drh
|
408 |
pzlib_filefunc_def->zseek_file = win32_seek_file_func; |
|
7ef7284…
|
drh
|
409 |
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
|
7ef7284…
|
drh
|
410 |
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
|
7ef7284…
|
drh
|
411 |
pzlib_filefunc_def->opaque = NULL; |
|
7ef7284…
|
drh
|
412 |
} |
|
7ef7284…
|
drh
|
413 |
|
|
f1f1d6c…
|
drh
|
414 |
void fill_win32_filefunc64(zlib_filefunc64_def* pzlib_filefunc_def) { |
|
7ef7284…
|
drh
|
415 |
pzlib_filefunc_def->zopen64_file = win32_open64_file_func; |
|
7ef7284…
|
drh
|
416 |
pzlib_filefunc_def->zread_file = win32_read_file_func; |
|
7ef7284…
|
drh
|
417 |
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
|
7ef7284…
|
drh
|
418 |
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; |
|
7ef7284…
|
drh
|
419 |
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; |
|
7ef7284…
|
drh
|
420 |
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
|
7ef7284…
|
drh
|
421 |
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
|
7ef7284…
|
drh
|
422 |
pzlib_filefunc_def->opaque = NULL; |
|
7ef7284…
|
drh
|
423 |
} |
|
7ef7284…
|
drh
|
424 |
|
|
7ef7284…
|
drh
|
425 |
|
|
f1f1d6c…
|
drh
|
426 |
void fill_win32_filefunc64A(zlib_filefunc64_def* pzlib_filefunc_def) { |
|
7ef7284…
|
drh
|
427 |
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcA; |
|
7ef7284…
|
drh
|
428 |
pzlib_filefunc_def->zread_file = win32_read_file_func; |
|
7ef7284…
|
drh
|
429 |
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
|
7ef7284…
|
drh
|
430 |
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; |
|
7ef7284…
|
drh
|
431 |
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; |
|
7ef7284…
|
drh
|
432 |
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
|
7ef7284…
|
drh
|
433 |
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
|
7ef7284…
|
drh
|
434 |
pzlib_filefunc_def->opaque = NULL; |
|
7ef7284…
|
drh
|
435 |
} |
|
7ef7284…
|
drh
|
436 |
|
|
7ef7284…
|
drh
|
437 |
|
|
f1f1d6c…
|
drh
|
438 |
void fill_win32_filefunc64W(zlib_filefunc64_def* pzlib_filefunc_def) { |
|
7ef7284…
|
drh
|
439 |
pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; |
|
7ef7284…
|
drh
|
440 |
pzlib_filefunc_def->zread_file = win32_read_file_func; |
|
7ef7284…
|
drh
|
441 |
pzlib_filefunc_def->zwrite_file = win32_write_file_func; |
|
7ef7284…
|
drh
|
442 |
pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; |
|
7ef7284…
|
drh
|
443 |
pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; |
|
7ef7284…
|
drh
|
444 |
pzlib_filefunc_def->zclose_file = win32_close_file_func; |
|
7ef7284…
|
drh
|
445 |
pzlib_filefunc_def->zerror_file = win32_error_file_func; |
|
7ef7284…
|
drh
|
446 |
pzlib_filefunc_def->opaque = NULL; |
|
7ef7284…
|
drh
|
447 |
} |