| 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)) | 13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS))) |
| 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 |
| 17 #include "ioapi.h" | 29 #include "ioapi.h" |
| 18 | 30 |
| 19 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename
,int mode) | 31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename
,int mode) |
| 20 { | 32 { |
| 21 if (pfilefunc->zfile_func64.zopen64_file != NULL) | 33 if (pfilefunc->zfile_func64.zopen64_file != NULL) |
| 22 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func6
4.opaque,filename,mode); | 34 return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func6
4.opaque,filename,mode); |
| 23 else | 35 else |
| 24 { | 36 { |
| 25 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(cons
t char*)filename,mode); | 37 return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(cons
t char*)filename,mode); |
| 26 } | 38 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 40 } | 52 } |
| 41 } | 53 } |
| 42 | 54 |
| 43 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
) | 55 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream
) |
| 44 { | 56 { |
| 45 if (pfilefunc->zfile_func64.zseek64_file != NULL) | 57 if (pfilefunc->zfile_func64.zseek64_file != NULL) |
| 46 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func6
4.opaque,filestream); | 58 return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func6
4.opaque,filestream); |
| 47 else | 59 else |
| 48 { | 60 { |
| 49 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.
opaque,filestream); | 61 uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.
opaque,filestream); |
| 50 if ((tell_uLong) == ((uLong)-1)) | 62 if ((tell_uLong) == MAXU32) |
| 51 return (ZPOS64_T)-1; | 63 return (ZPOS64_T)-1; |
| 52 else | 64 else |
| 53 return tell_uLong; | 65 return tell_uLong; |
| 54 } | 66 } |
| 55 } | 67 } |
| 56 | 68 |
| 57 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
unc64_32,const zlib_filefunc_def* p_filefunc32) | 69 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filef
unc64_32,const zlib_filefunc_def* p_filefunc32) |
| 58 { | 70 { |
| 59 p_filefunc64_32->zfile_func64.zopen64_file = NULL; | 71 p_filefunc64_32->zfile_func64.zopen64_file = NULL; |
| 60 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; | 72 p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) | 117 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) |
| 106 mode_fopen = "rb"; | 118 mode_fopen = "rb"; |
| 107 else | 119 else |
| 108 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) | 120 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) |
| 109 mode_fopen = "r+b"; | 121 mode_fopen = "r+b"; |
| 110 else | 122 else |
| 111 if (mode & ZLIB_FILEFUNC_MODE_CREATE) | 123 if (mode & ZLIB_FILEFUNC_MODE_CREATE) |
| 112 mode_fopen = "wb"; | 124 mode_fopen = "wb"; |
| 113 | 125 |
| 114 if ((filename!=NULL) && (mode_fopen != NULL)) | 126 if ((filename!=NULL) && (mode_fopen != NULL)) |
| 115 file = fopen64((const char*)filename, mode_fopen); | 127 file = FOPEN_FUNC((const char*)filename, mode_fopen); |
| 116 return file; | 128 return file; |
| 117 } | 129 } |
| 118 | 130 |
| 119 | 131 |
| 120 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf,
uLong size) | 132 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf,
uLong size) |
| 121 { | 133 { |
| 122 uLong ret; | 134 uLong ret; |
| 123 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); | 135 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream); |
| 124 return ret; | 136 return ret; |
| 125 } | 137 } |
| 126 | 138 |
| 127 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const voi
d* buf, uLong size) | 139 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const voi
d* buf, uLong size) |
| 128 { | 140 { |
| 129 uLong ret; | 141 uLong ret; |
| 130 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); | 142 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream); |
| 131 return ret; | 143 return ret; |
| 132 } | 144 } |
| 133 | 145 |
| 134 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) | 146 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream) |
| 135 { | 147 { |
| 136 long ret; | 148 long ret; |
| 137 ret = ftell((FILE *)stream); | 149 ret = ftell((FILE *)stream); |
| 138 return ret; | 150 return ret; |
| 139 } | 151 } |
| 140 | 152 |
| 141 | 153 |
| 142 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) | 154 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream) |
| 143 { | 155 { |
| 144 ZPOS64_T ret; | 156 ZPOS64_T ret; |
| 145 ret = ftello64((FILE *)stream); | 157 ret = FTELLO_FUNC((FILE *)stream); |
| 146 return ret; | 158 return ret; |
| 147 } | 159 } |
| 148 | 160 |
| 149 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
et, int origin) | 161 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offs
et, int origin) |
| 150 { | 162 { |
| 151 int fseek_origin=0; | 163 int fseek_origin=0; |
| 152 long ret; | 164 long ret; |
| 153 switch (origin) | 165 switch (origin) |
| 154 { | 166 { |
| 155 case ZLIB_FILEFUNC_SEEK_CUR : | 167 case ZLIB_FILEFUNC_SEEK_CUR : |
| (...skipping 25 matching lines...) Expand all Loading... |
| 181 case ZLIB_FILEFUNC_SEEK_END : | 193 case ZLIB_FILEFUNC_SEEK_END : |
| 182 fseek_origin = SEEK_END; | 194 fseek_origin = SEEK_END; |
| 183 break; | 195 break; |
| 184 case ZLIB_FILEFUNC_SEEK_SET : | 196 case ZLIB_FILEFUNC_SEEK_SET : |
| 185 fseek_origin = SEEK_SET; | 197 fseek_origin = SEEK_SET; |
| 186 break; | 198 break; |
| 187 default: return -1; | 199 default: return -1; |
| 188 } | 200 } |
| 189 ret = 0; | 201 ret = 0; |
| 190 | 202 |
| 191 if(fseeko64((FILE *)stream, offset, fseek_origin) != 0) | 203 if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0) |
| 192 ret = -1; | 204 ret = -1; |
| 193 | 205 |
| 194 return ret; | 206 return ret; |
| 195 } | 207 } |
| 196 | 208 |
| 197 | 209 |
| 198 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) | 210 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream) |
| 199 { | 211 { |
| 200 int ret; | 212 int ret; |
| 201 ret = fclose((FILE *)stream); | 213 ret = fclose((FILE *)stream); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 226 { | 238 { |
| 227 pzlib_filefunc_def->zopen64_file = fopen64_file_func; | 239 pzlib_filefunc_def->zopen64_file = fopen64_file_func; |
| 228 pzlib_filefunc_def->zread_file = fread_file_func; | 240 pzlib_filefunc_def->zread_file = fread_file_func; |
| 229 pzlib_filefunc_def->zwrite_file = fwrite_file_func; | 241 pzlib_filefunc_def->zwrite_file = fwrite_file_func; |
| 230 pzlib_filefunc_def->ztell64_file = ftell64_file_func; | 242 pzlib_filefunc_def->ztell64_file = ftell64_file_func; |
| 231 pzlib_filefunc_def->zseek64_file = fseek64_file_func; | 243 pzlib_filefunc_def->zseek64_file = fseek64_file_func; |
| 232 pzlib_filefunc_def->zclose_file = fclose_file_func; | 244 pzlib_filefunc_def->zclose_file = fclose_file_func; |
| 233 pzlib_filefunc_def->zerror_file = ferror_file_func; | 245 pzlib_filefunc_def->zerror_file = ferror_file_func; |
| 234 pzlib_filefunc_def->opaque = NULL; | 246 pzlib_filefunc_def->opaque = NULL; |
| 235 } | 247 } |
| OLD | NEW |