| OLD | NEW |
| 1 /* ioapi.h -- IO base function header for compress/uncompress .zip | 1 /* ioapi.h -- IO base function header for compress/uncompress .zip |
| 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html
) | 2 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html
) |
| 3 | 3 |
| 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) | 4 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.
com/zLibDll/minizip.html ) |
| 5 | 5 |
| 6 Modifications for Zip64 support | 6 Modifications for Zip64 support |
| 7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | 7 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) |
| 8 | 8 |
| 9 For more info read MiniZip_info.txt | 9 For more info read MiniZip_info.txt |
| 10 | 10 |
| 11 */ | 11 */ |
| 12 | 12 |
| 13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) | 13 #if (defined(_WIN32)) |
| 14 #define _CRT_SECURE_NO_WARNINGS | 14 #define _CRT_SECURE_NO_WARNINGS |
| 15 #endif | 15 #endif |
| 16 | 16 |
| 17 #if defined(__APPLE__) || defined(IOAPI_NO_64) | |
| 18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no ne
ed for specific 64 bit functions | |
| 19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode) | |
| 20 #define FTELLO_FUNC(stream) ftello(stream) | |
| 21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin) | |
| 22 #else | |
| 23 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode) | |
| 24 #define FTELLO_FUNC(stream) ftello64(stream) | |
| 25 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin) | |
| 26 #endif | |
| 27 | |
| 28 | |
| 29 #include "ioapi.h" | 17 #include "ioapi.h" |
| 30 | 18 |
| 31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename
,int mode) | 19 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename
,int mode) |
| 32 { | 20 { |
| 33 if (pfilefunc->zfile_func64.zopen64_file != NULL) | 21 if (pfilefunc->zfile_func64.zopen64_file != NULL) |
| 34 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func6
4.opaque,filename,mode); | 22 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func6
4.opaque,filename,mode); |
| 35 else | 23 else |
| 36 { | 24 { |
| 37 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(cons
t char*)filename,mode); | 25 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(cons
t char*)filename,mode); |
| 38 } | 26 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 52 } | 40 } |
| 53 } | 41 } |
| 54 | 42 |
| 55 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
) | 43 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
) |
| 56 { | 44 { |
| 57 if (pfilefunc->zfile_func64.zseek64_file != NULL) | 45 if (pfilefunc->zfile_func64.zseek64_file != NULL) |
| 58 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func6
4.opaque,filestream); | 46 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func6
4.opaque,filestream); |
| 59 else | 47 else |
| 60 { | 48 { |
| 61 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.
opaque,filestream); | 49 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.
opaque,filestream); |
| 62 if ((tell_uLong) == MAXU32) | 50 if ((tell_uLong) == ((uLong)-1)) |
| 63 return (ZPOS64_T)-1; | 51 return (ZPOS64_T)-1; |
| 64 else | 52 else |
| 65 return tell_uLong; | 53 return tell_uLong; |
| 66 } | 54 } |
| 67 } | 55 } |
| 68 | 56 |
| 69 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
unc64_32,const zlib_filefunc_def* p_filefunc32) | 57 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
unc64_32,const zlib_filefunc_def* p_filefunc32) |
| 70 { | 58 { |
| 71 p_filefunc64_32->zfile_func64.zopen64_file = NULL; | 59 p_filefunc64_32->zfile_func64.zopen64_file = NULL; |
| 72 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; | 60 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | 105 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
| 118 mode_fopen = "rb"; | 106 mode_fopen = "rb"; |
| 119 else | 107 else |
| 120 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | 108 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
| 121 mode_fopen = "r+b"; | 109 mode_fopen = "r+b"; |
| 122 else | 110 else |
| 123 if (mode & ZLIB_FILEFUNC_MODE_CREATE) | 111 if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
| 124 mode_fopen = "wb"; | 112 mode_fopen = "wb"; |
| 125 | 113 |
| 126 if ((filename!=NULL) && (mode_fopen != NULL)) | 114 if ((filename!=NULL) && (mode_fopen != NULL)) |
| 127 file = FOPEN_FUNC((const char*)filename, mode_fopen); | 115 file = fopen64((const char*)filename, mode_fopen); |
| 128 return file; | 116 return file; |
| 129 } | 117 } |
| 130 | 118 |
| 131 | 119 |
| 132 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf,
uLong size) | 120 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf,
uLong size) |
| 133 { | 121 { |
| 134 uLong ret; | 122 uLong ret; |
| 135 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | 123 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); |
| 136 return ret; | 124 return ret; |
| 137 } | 125 } |
| 138 | 126 |
| 139 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const voi
d* buf, uLong size) | 127 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const voi
d* buf, uLong size) |
| 140 { | 128 { |
| 141 uLong ret; | 129 uLong ret; |
| 142 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | 130 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); |
| 143 return ret; | 131 return ret; |
| 144 } | 132 } |
| 145 | 133 |
| 146 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) | 134 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) |
| 147 { | 135 { |
| 148 long ret; | 136 long ret; |
| 149 ret = ftell((FILE *)stream); | 137 ret = ftell((FILE *)stream); |
| 150 return ret; | 138 return ret; |
| 151 } | 139 } |
| 152 | 140 |
| 153 | 141 |
| 154 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) | 142 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) |
| 155 { | 143 { |
| 156 ZPOS64_T ret; | 144 ZPOS64_T ret; |
| 157 ret = FTELLO_FUNC((FILE *)stream); | 145 ret = ftello64((FILE *)stream); |
| 158 return ret; | 146 return ret; |
| 159 } | 147 } |
| 160 | 148 |
| 161 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
et, int origin) | 149 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
et, int origin) |
| 162 { | 150 { |
| 163 int fseek_origin=0; | 151 int fseek_origin=0; |
| 164 long ret; | 152 long ret; |
| 165 switch (origin) | 153 switch (origin) |
| 166 { | 154 { |
| 167 case ZLIB_FILEFUNC_SEEK_CUR : | 155 case ZLIB_FILEFUNC_SEEK_CUR : |
| (...skipping 25 matching lines...) Expand all Loading... |
| 193 case ZLIB_FILEFUNC_SEEK_END : | 181 case ZLIB_FILEFUNC_SEEK_END : |
| 194 fseek_origin = SEEK_END; | 182 fseek_origin = SEEK_END; |
| 195 break; | 183 break; |
| 196 case ZLIB_FILEFUNC_SEEK_SET : | 184 case ZLIB_FILEFUNC_SEEK_SET : |
| 197 fseek_origin = SEEK_SET; | 185 fseek_origin = SEEK_SET; |
| 198 break; | 186 break; |
| 199 default: return -1; | 187 default: return -1; |
| 200 } | 188 } |
| 201 ret = 0; | 189 ret = 0; |
| 202 | 190 |
| 203 if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) | 191 if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) |
| 204 ret = -1; | 192 ret = -1; |
| 205 | 193 |
| 206 return ret; | 194 return ret; |
| 207 } | 195 } |
| 208 | 196 |
| 209 | 197 |
| 210 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) | 198 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) |
| 211 { | 199 { |
| 212 int ret; | 200 int ret; |
| 213 ret = fclose((FILE *)stream); | 201 ret = fclose((FILE *)stream); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 238 { | 226 { |
| 239 pzlib_filefunc_def->zopen64_file = fopen64_file_func; | 227 pzlib_filefunc_def->zopen64_file = fopen64_file_func; |
| 240 pzlib_filefunc_def->zread_file = fread_file_func; | 228 pzlib_filefunc_def->zread_file = fread_file_func; |
| 241 pzlib_filefunc_def->zwrite_file = fwrite_file_func; | 229 pzlib_filefunc_def->zwrite_file = fwrite_file_func; |
| 242 pzlib_filefunc_def->ztell64_file = ftell64_file_func; | 230 pzlib_filefunc_def->ztell64_file = ftell64_file_func; |
| 243 pzlib_filefunc_def->zseek64_file = fseek64_file_func; | 231 pzlib_filefunc_def->zseek64_file = fseek64_file_func; |
| 244 pzlib_filefunc_def->zclose_file = fclose_file_func; | 232 pzlib_filefunc_def->zclose_file = fclose_file_func; |
| 245 pzlib_filefunc_def->zerror_file = ferror_file_func; | 233 pzlib_filefunc_def->zerror_file = ferror_file_func; |
| 246 pzlib_filefunc_def->opaque = NULL; | 234 pzlib_filefunc_def->opaque = NULL; |
| 247 } | 235 } |
| OLD | NEW |