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

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

Issue 2084863002: 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
28 voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode)); 42 voidpf ZCALLBACK win32_open_file_func OF((voidpf opaque, const char* filename, int mode));
29 uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 43 uLong ZCALLBACK win32_read_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
30 uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 44 uLong ZCALLBACK win32_write_file_func OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
31 ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream)); 45 ZPOS64_T ZCALLBACK win32_tell64_file_func OF((voidpf opaque, voidpf stream));
32 long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS 64_T offset, int origin)); 46 long ZCALLBACK win32_seek64_file_func OF((voidpf opaque, voidpf stream, ZPOS 64_T offset, int origin));
33 int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream)); 47 int ZCALLBACK win32_close_file_func OF((voidpf opaque, voidpf stream));
34 int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream)); 48 int ZCALLBACK win32_error_file_func OF((voidpf opaque, voidpf stream));
35 49
36 typedef struct 50 typedef struct
37 { 51 {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 } 100 }
87 101
88 voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode) 102 voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int mode)
89 { 103 {
90 const char* mode_fopen = NULL; 104 const char* mode_fopen = NULL;
91 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 105 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
92 HANDLE hFile = NULL; 106 HANDLE hFile = NULL;
93 107
94 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 108 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
95 109
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
96 if ((filename!=NULL) && (dwDesiredAccess != 0)) 123 if ((filename!=NULL) && (dwDesiredAccess != 0))
97 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 124 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
125 #endif
98 126
99 return win32_build_iowin(hFile); 127 return win32_build_iowin(hFile);
100 } 128 }
101 129
102 130
103 voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode) 131 voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int mode)
104 { 132 {
105 const char* mode_fopen = NULL; 133 const char* mode_fopen = NULL;
106 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 134 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
107 HANDLE hFile = NULL; 135 HANDLE hFile = NULL;
108 136
109 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 137 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
110 138
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
111 if ((filename!=NULL) && (dwDesiredAccess != 0)) 147 if ((filename!=NULL) && (dwDesiredAccess != 0))
112 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 148 hFile = CreateFileA((LPCSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
149 #endif
113 150
114 return win32_build_iowin(hFile); 151 return win32_build_iowin(hFile);
115 } 152 }
116 153
117 154
118 voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode) 155 voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int mode)
119 { 156 {
120 const char* mode_fopen = NULL; 157 const char* mode_fopen = NULL;
121 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 158 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
122 HANDLE hFile = NULL; 159 HANDLE hFile = NULL;
123 160
124 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 161 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
125 162
163 #ifdef IOWIN32_USING_WINRT_API
164 if ((filename!=NULL) && (dwDesiredAccess != 0))
165 hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwC reationDisposition,NULL);
166 #else
126 if ((filename!=NULL) && (dwDesiredAccess != 0)) 167 if ((filename!=NULL) && (dwDesiredAccess != 0))
127 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NUL L, dwCreationDisposition, dwFlagsAndAttributes, NULL); 168 hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NUL L, dwCreationDisposition, dwFlagsAndAttributes, NULL);
169 #endif
128 170
129 return win32_build_iowin(hFile); 171 return win32_build_iowin(hFile);
130 } 172 }
131 173
132 174
133 voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mo de) 175 voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mo de)
134 { 176 {
135 const char* mode_fopen = NULL; 177 const char* mode_fopen = NULL;
136 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 178 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
137 HANDLE hFile = NULL; 179 HANDLE hFile = NULL;
138 180
139 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes); 181 win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwSh areMode,&dwFlagsAndAttributes);
140 182
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
141 if ((filename!=NULL) && (dwDesiredAccess != 0)) 196 if ((filename!=NULL) && (dwDesiredAccess != 0))
142 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL); 197 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL , dwCreationDisposition, dwFlagsAndAttributes, NULL);
198 #endif
143 199
144 return win32_build_iowin(hFile); 200 return win32_build_iowin(hFile);
145 } 201 }
146 202
147 203
148 uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uL ong size) 204 uLong ZCALLBACK win32_read_file_func (voidpf opaque, voidpf stream, void* buf,uL ong size)
149 { 205 {
150 uLong ret=0; 206 uLong ret=0;
151 HANDLE hFile = NULL; 207 HANDLE hFile = NULL;
152 if (stream!=NULL) 208 if (stream!=NULL)
(...skipping 28 matching lines...) Expand all
181 DWORD dwErr = GetLastError(); 237 DWORD dwErr = GetLastError();
182 if (dwErr == ERROR_HANDLE_EOF) 238 if (dwErr == ERROR_HANDLE_EOF)
183 dwErr = 0; 239 dwErr = 0;
184 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 240 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
185 } 241 }
186 } 242 }
187 243
188 return ret; 244 return ret;
189 } 245 }
190 246
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
191 long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) 267 long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream)
192 { 268 {
193 long ret=-1; 269 long ret=-1;
194 HANDLE hFile = NULL; 270 HANDLE hFile = NULL;
195 if (stream!=NULL) 271 if (stream!=NULL)
196 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 272 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
197 if (hFile != NULL) 273 if (hFile != NULL)
198 { 274 {
199 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); 275 LARGE_INTEGER pos;
200 if (dwSet == INVALID_SET_FILE_POINTER) 276 pos.QuadPart = 0;
277
278 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
201 { 279 {
202 DWORD dwErr = GetLastError(); 280 DWORD dwErr = GetLastError();
203 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 281 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
204 ret = -1; 282 ret = -1;
205 } 283 }
206 else 284 else
207 ret=(long)dwSet; 285 ret=(long)pos.LowPart;
208 } 286 }
209 return ret; 287 return ret;
210 } 288 }
211 289
212 ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) 290 ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream)
213 { 291 {
214 ZPOS64_T ret= (ZPOS64_T)-1; 292 ZPOS64_T ret= (ZPOS64_T)-1;
215 HANDLE hFile = NULL; 293 HANDLE hFile = NULL;
216 if (stream!=NULL) 294 if (stream!=NULL)
217 hFile = ((WIN32FILE_IOWIN*)stream)->hf; 295 hFile = ((WIN32FILE_IOWIN*)stream)->hf;
218 296
219 if (hFile) 297 if (hFile)
220 { 298 {
221 LARGE_INTEGER li; 299 LARGE_INTEGER pos;
222 li.QuadPart = 0; 300 pos.QuadPart = 0;
223 li.u.LowPart = SetFilePointer(hFile, li.u.LowPart, &li.u.HighPart, FILE_ CURRENT); 301
224 if ( (li.LowPart == 0xFFFFFFFF) && (GetLastError() != NO_ERROR)) 302 if (!MySetFilePointerEx(hFile, pos, &pos, FILE_CURRENT))
225 { 303 {
226 DWORD dwErr = GetLastError(); 304 DWORD dwErr = GetLastError();
227 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 305 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
228 ret = (ZPOS64_T)-1; 306 ret = (ZPOS64_T)-1;
229 } 307 }
230 else 308 else
231 ret=li.QuadPart; 309 ret=pos.QuadPart;
232 } 310 }
233 return ret; 311 return ret;
234 } 312 }
235 313
236 314
237 long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,in t origin) 315 long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,in t origin)
238 { 316 {
239 DWORD dwMoveMethod=0xFFFFFFFF; 317 DWORD dwMoveMethod=0xFFFFFFFF;
240 HANDLE hFile = NULL; 318 HANDLE hFile = NULL;
241 319
242 long ret=-1; 320 long ret=-1;
243 if (stream!=NULL) 321 if (stream!=NULL)
244 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 322 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
245 switch (origin) 323 switch (origin)
246 { 324 {
247 case ZLIB_FILEFUNC_SEEK_CUR : 325 case ZLIB_FILEFUNC_SEEK_CUR :
248 dwMoveMethod = FILE_CURRENT; 326 dwMoveMethod = FILE_CURRENT;
249 break; 327 break;
250 case ZLIB_FILEFUNC_SEEK_END : 328 case ZLIB_FILEFUNC_SEEK_END :
251 dwMoveMethod = FILE_END; 329 dwMoveMethod = FILE_END;
252 break; 330 break;
253 case ZLIB_FILEFUNC_SEEK_SET : 331 case ZLIB_FILEFUNC_SEEK_SET :
254 dwMoveMethod = FILE_BEGIN; 332 dwMoveMethod = FILE_BEGIN;
255 break; 333 break;
256 default: return -1; 334 default: return -1;
257 } 335 }
258 336
259 if (hFile != NULL) 337 if (hFile != NULL)
260 { 338 {
261 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); 339 LARGE_INTEGER pos;
262 if (dwSet == INVALID_SET_FILE_POINTER) 340 pos.QuadPart = offset;
341 if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
263 { 342 {
264 DWORD dwErr = GetLastError(); 343 DWORD dwErr = GetLastError();
265 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 344 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
266 ret = -1; 345 ret = -1;
267 } 346 }
268 else 347 else
269 ret=0; 348 ret=0;
270 } 349 }
271 return ret; 350 return ret;
272 } 351 }
(...skipping 16 matching lines...) Expand all
289 dwMoveMethod = FILE_END; 368 dwMoveMethod = FILE_END;
290 break; 369 break;
291 case ZLIB_FILEFUNC_SEEK_SET : 370 case ZLIB_FILEFUNC_SEEK_SET :
292 dwMoveMethod = FILE_BEGIN; 371 dwMoveMethod = FILE_BEGIN;
293 break; 372 break;
294 default: return -1; 373 default: return -1;
295 } 374 }
296 375
297 if (hFile) 376 if (hFile)
298 { 377 {
299 LARGE_INTEGER* li = (LARGE_INTEGER*)&offset; 378 LARGE_INTEGER pos;
300 DWORD dwSet = SetFilePointer(hFile, li->u.LowPart, &li->u.HighPart, dwMo veMethod); 379 pos.QuadPart = offset;
301 if (dwSet == INVALID_SET_FILE_POINTER) 380 if (!MySetFilePointerEx(hFile, pos, NULL, dwMoveMethod))
302 { 381 {
303 DWORD dwErr = GetLastError(); 382 DWORD dwErr = GetLastError();
304 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 383 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
305 ret = -1; 384 ret = -1;
306 } 385 }
307 else 386 else
308 ret=0; 387 ret=0;
309 } 388 }
310 return ret; 389 return ret;
311 } 390 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 { 459 {
381 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW; 460 pzlib_filefunc_def->zopen64_file = win32_open64_file_funcW;
382 pzlib_filefunc_def->zread_file = win32_read_file_func; 461 pzlib_filefunc_def->zread_file = win32_read_file_func;
383 pzlib_filefunc_def->zwrite_file = win32_write_file_func; 462 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
384 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func; 463 pzlib_filefunc_def->ztell64_file = win32_tell64_file_func;
385 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func; 464 pzlib_filefunc_def->zseek64_file = win32_seek64_file_func;
386 pzlib_filefunc_def->zclose_file = win32_close_file_func; 465 pzlib_filefunc_def->zclose_file = win32_close_file_func;
387 pzlib_filefunc_def->zerror_file = win32_error_file_func; 466 pzlib_filefunc_def->zerror_file = win32_error_file_func;
388 pzlib_filefunc_def->opaque = NULL; 467 pzlib_filefunc_def->opaque = NULL;
389 } 468 }
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