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

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

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

Powered by Google App Engine
This is Rietveld 408576698