diff options
| author | Mark Adler <madler@alumni.caltech.edu> | 2013-04-14 10:05:43 -0700 |
|---|---|---|
| committer | Mark Adler <madler@alumni.caltech.edu> | 2013-04-28 15:57:11 -0700 |
| commit | 5481269e1fa6d99a1799762c657f1ba7155ad922 (patch) | |
| tree | 761b72326b15460ddc425608f0d61cac6c13d71d | |
| parent | e8fee0ea7bf62e595bd5518b7b22e3e16397278c (diff) | |
| download | zlib-5481269e1fa6d99a1799762c657f1ba7155ad922.tar.gz zlib-5481269e1fa6d99a1799762c657f1ba7155ad922.tar.bz2 zlib-5481269e1fa6d99a1799762c657f1ba7155ad922.zip | |
Update contrib/minizip/iowin32.c for Windows RT [Vollant].
| -rw-r--r-- | contrib/minizip/iowin32.c | 98 |
1 files changed, 85 insertions, 13 deletions
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c index 6a2a883..a46d96c 100644 --- a/contrib/minizip/iowin32.c +++ b/contrib/minizip/iowin32.c | |||
| @@ -25,6 +25,13 @@ | |||
| 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)); |
| @@ -93,8 +100,22 @@ voidpf ZCALLBACK win32_open64_file_func (voidpf opaque,const void* filename,int | |||
| 93 | 100 | ||
| 94 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); | 101 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&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, dwCreationDisposition, 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, dwCreationDisposition, 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 | } |
| @@ -108,8 +129,17 @@ voidpf ZCALLBACK win32_open64_file_funcA (voidpf opaque,const void* filename,int | |||
| 108 | 129 | ||
| 109 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); | 130 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&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, dwCreationDisposition, 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 | } |
| @@ -123,8 +153,13 @@ voidpf ZCALLBACK win32_open64_file_funcW (voidpf opaque,const void* filename,int | |||
| 123 | 153 | ||
| 124 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); | 154 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); |
| 125 | 155 | ||
| 156 | #ifdef IOWIN32_USING_WINRT_API | ||
| 157 | if ((filename!=NULL) && (dwDesiredAccess != 0)) | ||
| 158 | hFile = CreateFile2((LPCWSTR)filename, dwDesiredAccess, dwShareMode, dwCreationDisposition,NULL); | ||
| 159 | #else | ||
| 126 | if ((filename!=NULL) && (dwDesiredAccess != 0)) | 160 | if ((filename!=NULL) && (dwDesiredAccess != 0)) |
| 127 | hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); | 161 | hFile = CreateFileW((LPCWSTR)filename, dwDesiredAccess, dwShareMode, NULL, dwCreationDisposition, dwFlagsAndAttributes, NULL); |
| 162 | #endif | ||
| 128 | 163 | ||
| 129 | return win32_build_iowin(hFile); | 164 | return win32_build_iowin(hFile); |
| 130 | } | 165 | } |
| @@ -138,8 +173,22 @@ voidpf ZCALLBACK win32_open_file_func (voidpf opaque,const char* filename,int mo | |||
| 138 | 173 | ||
| 139 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&dwFlagsAndAttributes); | 174 | win32_translate_open_mode(mode,&dwDesiredAccess,&dwCreationDisposition,&dwShareMode,&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, dwCreationDisposition, 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, dwCreationDisposition, 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 | } |
| @@ -188,6 +237,26 @@ uLong ZCALLBACK win32_write_file_func (voidpf opaque,voidpf stream,const void* b | |||
| 188 | return ret; | 237 | return ret; |
| 189 | } | 238 | } |
| 190 | 239 | ||
| 240 | static BOOL MySetFilePointerEx(HANDLE hFile, LARGE_INTEGER pos, LARGE_INTEGER *newPos, 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; |
| @@ -196,15 +265,17 @@ long ZCALLBACK win32_tell_file_func (voidpf opaque,voidpf stream) | |||
| 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 | } |
| @@ -218,17 +289,17 @@ ZPOS64_T ZCALLBACK win32_tell64_file_func (voidpf opaque, voidpf stream) | |||
| 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 | } |
| @@ -258,8 +329,9 @@ long ZCALLBACK win32_seek_file_func (voidpf opaque,voidpf stream,uLong offset,in | |||
| 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; |
| @@ -296,9 +368,9 @@ long ZCALLBACK win32_seek64_file_func (voidpf opaque, voidpf stream,ZPOS64_T off | |||
| 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, dwMoveMethod); | 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; |
