Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(411)

Side by Side Diff: third_party/zlib/contrib/minizip/iowin32.c

Issue 2079313002: Revert of Update Zlib to version 1.2.8 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/zlib/contrib/minizip/ioapi.c ('k') | third_party/zlib/contrib/minizip/miniunz.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* iowin32.c -- IO base function header for compress/uncompress .zip 1 /* iowin32.c -- IO base function header for compress/uncompress .zip
2 Version 1.1, February 14h, 2010 2 Version 1.1, February 14h, 2010
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.htm l ) 3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.htm l )
4 4
5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage. com/zLibDll/minizip.html ) 5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage. com/zLibDll/minizip.html )
6 6
7 Modifications for Zip64 support 7 Modifications for Zip64 support
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) 8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
9 9
10 For more info read MiniZip_info.txt 10 For more info read MiniZip_info.txt
11 11
12 */ 12 */
13 13
14 #include <stdlib.h> 14 #include <stdlib.h>
15 15
16 #include "zlib.h" 16 #include "zlib.h"
17 #include "ioapi.h" 17 #include "ioapi.h"
18 #include "iowin32.h" 18 #include "iowin32.h"
19 19
20 #ifndef INVALID_HANDLE_VALUE 20 #ifndef INVALID_HANDLE_VALUE
21 #define INVALID_HANDLE_VALUE (0xFFFFFFFF) 21 #define INVALID_HANDLE_VALUE (0xFFFFFFFF)
22 #endif 22 #endif
23 23
24 #ifndef INVALID_SET_FILE_POINTER 24 #ifndef INVALID_SET_FILE_POINTER
25 #define INVALID_SET_FILE_POINTER ((DWORD)-1) 25 #define INVALID_SET_FILE_POINTER ((DWORD)-1)
26 #endif 26 #endif
27 27
28
29 #ifdef _WIN32_WINNT
30 #undef _WIN32_WINNT
31 #define _WIN32_WINNT 0x601
32 #endif
33
34 #if _WIN32_WINNT >= _WIN32_WINNT_WIN8
35 #if defined(WINAPI_FAMILY_PARTITION) && (!(defined(IOWIN32_USING_WINRT_API)))
36 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
37 #define IOWIN32_USING_WINRT_API 1
38 #endif
39 #endif
40 #endif
41
42 voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); 28 voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
43 uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 29 uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
44 uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 30 uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
45 ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); 31 ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
46 long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS 64_T offset, int origin)); 32 long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS 64_T offset, int origin));
47 int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); 33 int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
48 int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); 34 int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
49 35
50 typedef struct 36 typedef struct
51 { 37 {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 86 }
101 87
102 voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) 88 voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
103 { 89 {
104 const char* mode_fopen = NULL; 90 const char* mode_fopen = NULL;
105 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 91 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
106 HANDLE hFile = NULL; 92 HANDLE hFile = NULL;
107 93
108 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 94 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
109 95
110 #ifdef IOWIN32_USING_WINRT_API
111 #ifdef UNICODE
112 if ((filename!=NULL) && (dwDesiredAccess != 0))
113 hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwC reationDisposition, NULL);
114 #else
115 if ((filename!=NULL) && (dwDesiredAccess != 0))
116 {
117 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
118 MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME _MAX + 0x200);
119 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationD isposition, NULL);
120 }
121 #endif
122 #else
123 if ((filename!=NULL) && (dwDesiredAccess != 0)) 96 if ((filename!=NULL) && (dwDesiredAccess != 0))
124 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 97 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
125 #endif
126 98
127 return win32_build_iowin(hFile); 99 return win32_build_iowin(hFile);
128 } 100 }
129 101
130 102
131 voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) 103 voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
132 { 104 {
133 const char* mode_fopen = NULL; 105 const char* mode_fopen = NULL;
134 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 106 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
135 HANDLE hFile = NULL; 107 HANDLE hFile = NULL;
136 108
137 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 109 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
138 110
139 #ifdef IOWIN32_USING_WINRT_API
140 if ((filename!=NULL) && (dwDesiredAccess != 0))
141 {
142 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
143 MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME _MAX + 0x200);
144 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationD isposition, NULL);
145 }
146 #else
147 if ((filename!=NULL) && (dwDesiredAccess != 0)) 111 if ((filename!=NULL) && (dwDesiredAccess != 0))
148 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 112 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
149 #endif
150 113
151 return win32_build_iowin(hFile); 114 return win32_build_iowin(hFile);
152 } 115 }
153 116
154 117
155 voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) 118 voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
156 { 119 {
157 const char* mode_fopen = NULL; 120 const char* mode_fopen = NULL;
158 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 121 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
159 HANDLE hFile = NULL; 122 HANDLE hFile = NULL;
160 123
161 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 124 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
162 125
163 #ifdef IOWIN32_USING_WINRT_API
164 if ((filename!=NULL) && (dwDesiredAccess != 0))
165 hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwC reationDisposition,NULL);
166 #else
167 if ((filename!=NULL) && (dwDesiredAccess != 0)) 126 if ((filename!=NULL) && (dwDesiredAccess != 0))
168 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NUL L, dwCreationDisposition, dwFlagsAndAttributes, NULL); 127 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NUL L, dwCreationDisposition, dwFlagsAndAttributes, NULL);
169 #endif
170 128
171 return win32_build_iowin(hFile); 129 return win32_build_iowin(hFile);
172 } 130 }
173 131
174 132
175 voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mo de) 133 voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mo de)
176 { 134 {
177 const char* mode_fopen = NULL; 135 const char* mode_fopen = NULL;
178 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 136 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
179 HANDLE hFile = NULL; 137 HANDLE hFile = NULL;
180 138
181 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 139 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
182 140
183 #ifdef IOWIN32_USING_WINRT_API
184 #ifdef UNICODE
185 if ((filename!=NULL) && (dwDesiredAccess != 0))
186 hFile = CreateFile2((LPCTSTR)filename, dwDesiredAccess, dwShareMode, dwC reationDisposition, NULL);
187 #else
188 if ((filename!=NULL) && (dwDesiredAccess != 0))
189 {
190 WCHAR filenameW[FILENAME_MAX + 0x200 + 1];
191 MultiByteToWideChar(CP_ACP,0,(const char*)filename,-1,filenameW,FILENAME _MAX + 0x200);
192 hFile = CreateFile2(filenameW, dwDesiredAccess, dwShareMode, dwCreationD isposition, NULL);
193 }
194 #endif
195 #else
196 if ((filename!=NULL) && (dwDesiredAccess != 0)) 141 if ((filename!=NULL) && (dwDesiredAccess != 0))
197 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 142 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
198 #endif
199 143
200 return win32_build_iowin(hFile); 144 return win32_build_iowin(hFile);
201 } 145 }
202 146
203 147
204 uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uL ong size) 148 uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uL ong size)
205 { 149 {
206 uLong ret=0; 150 uLong ret=0;
207 HANDLE hFile = NULL; 151 HANDLE hFile = NULL;
208 if (stream!=NULL) 152 if (stream!=NULL)
(...skipping 28 matching lines...) Expand all
237 DWORD dwErr = GetLastError(); 181 DWORD dwErr = GetLastError();
238 if (dwErr == ERROR_HANDLE_EOF) 182 if (dwErr == ERROR_HANDLE_EOF)
239 dwErr = 0; 183 dwErr = 0;
240 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 184 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
241 } 185 }
242 } 186 }
243 187
244 return ret; 188 return ret;
245 } 189 }
246 190
247 static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *n ewPos, DWORD dwMoveMethod)
248 {
249 #ifdef IOWIN32_USING_WINRT_API
250 return SetFilePointerEx(hFile, pos, newPos, dwMoveMethod);
251 #else
252 LONG lHigh = pos.HighPart;
253 DWORD dwNewPos = SetFilePointer(hFile, pos.LowPart, &lHigh, dwMoveMethod);
254 BOOL fOk = TRUE;
255 if (dwNewPos == 0xFFFFFFFF)
256 if (GetLastError() != NO_ERROR)
257 fOk = FALSE;
258 if ((newPos != NULL) && (fOk))
259 {
260 newPos->LowPart = dwNewPos;
261 newPos->HighPart = lHigh;
262 }
263 return fOk;
264 #endif
265 }
266
267 long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) 191 long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
268 { 192 {
269 long ret=-1; 193 long ret=-1;
270 HANDLE hFile = NULL; 194 HANDLE hFile = NULL;
271 if (stream!=NULL) 195 if (stream!=NULL)
272 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 196 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
273 if (hFile != NULL) 197 if (hFile != NULL)
274 { 198 {
275 LARGE_INTEGER pos; 199 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
276 pos.QuadPart = 0; 200 if (dwSet == INVALID_SET_FILE_POINTER)
277
278 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
279 { 201 {
280 DWORD dwErr = GetLastError(); 202 DWORD dwErr = GetLastError();
281 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 203 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
282 ret = -1; 204 ret = -1;
283 } 205 }
284 else 206 else
285 ret=(long)pos.LowPart; 207 ret=(long)dwSet;
286 } 208 }
287 return ret; 209 return ret;
288 } 210 }
289 211
290 ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) 212 ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
291 { 213 {
292 ZPOS64_T ret= (ZPOS64_T)-1; 214 ZPOS64_T ret= (ZPOS64_T)-1;
293 HANDLE hFile = NULL; 215 HANDLE hFile = NULL;
294 if (stream!=NULL) 216 if (stream!=NULL)
295 hFile = ((WIN32FILE_IOWIN*)stream)->hf; 217 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
296 218
297 if (hFile) 219 if (hFile)
298 { 220 {
299 LARGE_INTEGER pos; 221 LARGE_INTEGER li;
300 pos.QuadPart = 0; 222 li.QuadPart = 0;
301 223 li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_ CURRENT);
302 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT)) 224 if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR))
303 { 225 {
304 DWORD dwErr = GetLastError(); 226 DWORD dwErr = GetLastError();
305 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 227 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
306 ret = (ZPOS64_T)-1; 228 ret = (ZPOS64_T)-1;
307 } 229 }
308 else 230 else
309 ret=pos.QuadPart; 231 ret=li.QuadPart;
310 } 232 }
311 return ret; 233 return ret;
312 } 234 }
313 235
314 236
315 long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,in t origin) 237 long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,in t origin)
316 { 238 {
317 DWORD dwMoveMethod=0xFFFFFFFF; 239 DWORD dwMoveMethod=0xFFFFFFFF;
318 HANDLE hFile = NULL; 240 HANDLE hFile = NULL;
319 241
320 long ret=-1; 242 long ret=-1;
321 if (stream!=NULL) 243 if (stream!=NULL)
322 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 244 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
323 switch (origin) 245 switch (origin)
324 { 246 {
325 case ZLIB_FILEFUNC_SEEK_CUR : 247 case ZLIB_FILEFUNC_SEEK_CUR :
326 dwMoveMethod = FILE_CURRENT; 248 dwMoveMethod = FILE_CURRENT;
327 break; 249 break;
328 case ZLIB_FILEFUNC_SEEK_END : 250 case ZLIB_FILEFUNC_SEEK_END :
329 dwMoveMethod = FILE_END; 251 dwMoveMethod = FILE_END;
330 break; 252 break;
331 case ZLIB_FILEFUNC_SEEK_SET : 253 case ZLIB_FILEFUNC_SEEK_SET :
332 dwMoveMethod = FILE_BEGIN; 254 dwMoveMethod = FILE_BEGIN;
333 break; 255 break;
334 default: return -1; 256 default: return -1;
335 } 257 }
336 258
337 if (hFile != NULL) 259 if (hFile != NULL)
338 { 260 {
339 LARGE_INTEGER pos; 261 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
340 pos.QuadPart = offset; 262 if (dwSet == INVALID_SET_FILE_POINTER)
341 if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
342 { 263 {
343 DWORD dwErr = GetLastError(); 264 DWORD dwErr = GetLastError();
344 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 265 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
345 ret = -1; 266 ret = -1;
346 } 267 }
347 else 268 else
348 ret=0; 269 ret=0;
349 } 270 }
350 return ret; 271 return ret;
351 } 272 }
(...skipping 16 matching lines...) Expand all
368 dwMoveMethod = FILE_END; 289 dwMoveMethod = FILE_END;
369 break; 290 break;
370 case ZLIB_FILEFUNC_SEEK_SET : 291 case ZLIB_FILEFUNC_SEEK_SET :
371 dwMoveMethod = FILE_BEGIN; 292 dwMoveMethod = FILE_BEGIN;
372 break; 293 break;
373 default: return -1; 294 default: return -1;
374 } 295 }
375 296
376 if (hFile) 297 if (hFile)
377 { 298 {
378 LARGE_INTEGER pos; 299 LARGE_INTEGER* li = (LARGE_INTEGER*)&offset;
379 pos.QuadPart = offset; 300 DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMo veMethod);
380 if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod)) 301 if (dwSet == INVALID_SET_FILE_POINTER)
381 { 302 {
382 DWORD dwErr = GetLastError(); 303 DWORD dwErr = GetLastError();
383 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 304 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
384 ret = -1; 305 ret = -1;
385 } 306 }
386 else 307 else
387 ret=0; 308 ret=0;
388 } 309 }
389 return ret; 310 return ret;
390 } 311 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 { 380 {
460 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; 381 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
461 pzlib_filefunc_def->zread_file = win32_read_file_func; 382 pzlib_filefunc_def->zread_file = win32_read_file_func;
462 pzlib_filefunc_def->zwrite_file = win32_write_file_func; 383 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
463 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; 384 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
464 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; 385 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
465 pzlib_filefunc_def->zclose_file = win32_close_file_func; 386 pzlib_filefunc_def->zclose_file = win32_close_file_func;
466 pzlib_filefunc_def->zerror_file = win32_error_file_func; 387 pzlib_filefunc_def->zerror_file = win32_error_file_func;
467 pzlib_filefunc_def->opaque = NULL; 388 pzlib_filefunc_def->opaque = NULL;
468 } 389 }
OLDNEW
« no previous file with comments | « third_party/zlib/contrib/minizip/ioapi.c ('k') | third_party/zlib/contrib/minizip/miniunz.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698