| [1049] | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip | 
|---|
|  | 2 | part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) | 
|---|
|  | 3 |  | 
|---|
|  | 4 | Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) | 
|---|
|  | 5 |  | 
|---|
|  | 6 | Modifications for Zip64 support | 
|---|
|  | 7 | Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) | 
|---|
|  | 8 |  | 
|---|
|  | 9 | Modified by Sergey A. Tachenov to allow QIODevice API usage. | 
|---|
|  | 10 |  | 
|---|
|  | 11 | For more info read MiniZip_info.txt | 
|---|
|  | 12 |  | 
|---|
|  | 13 | Changes | 
|---|
|  | 14 |  | 
|---|
|  | 15 | Oct-2009 - Defined ZPOS64_T to fpos_t on windows and u_int64_t on linux. (might need to find a better why for this) | 
|---|
|  | 16 | Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. | 
|---|
|  | 17 | More if/def section may be needed to support other platforms | 
|---|
|  | 18 | Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. | 
|---|
|  | 19 | (but you should use iowin32.c for windows instead) | 
|---|
|  | 20 |  | 
|---|
|  | 21 | */ | 
|---|
|  | 22 |  | 
|---|
|  | 23 | #ifndef _ZLIBIOAPI64_H | 
|---|
|  | 24 | #define _ZLIBIOAPI64_H | 
|---|
|  | 25 |  | 
|---|
|  | 26 | #if (!defined(_WIN32)) && (!defined(WIN32)) | 
|---|
|  | 27 |  | 
|---|
|  | 28 | // Linux needs this to support file operation on files larger then 4+GB | 
|---|
|  | 29 | // But might need better if/def to select just the platforms that needs them. | 
|---|
|  | 30 |  | 
|---|
|  | 31 | #ifndef __USE_FILE_OFFSET64 | 
|---|
|  | 32 | #define __USE_FILE_OFFSET64 | 
|---|
|  | 33 | #endif | 
|---|
|  | 34 | #ifndef __USE_LARGEFILE64 | 
|---|
|  | 35 | #define __USE_LARGEFILE64 | 
|---|
|  | 36 | #endif | 
|---|
|  | 37 | #ifndef _LARGEFILE64_SOURCE | 
|---|
|  | 38 | #define _LARGEFILE64_SOURCE | 
|---|
|  | 39 | #endif | 
|---|
|  | 40 | #ifndef _FILE_OFFSET_BIT | 
|---|
|  | 41 | #define _FILE_OFFSET_BIT 64 | 
|---|
|  | 42 | #endif | 
|---|
|  | 43 | #endif | 
|---|
|  | 44 |  | 
|---|
|  | 45 | #include <stdio.h> | 
|---|
|  | 46 | #include <stdlib.h> | 
|---|
|  | 47 | #include "zlib.h" | 
|---|
|  | 48 |  | 
|---|
|  | 49 | #if defined(USE_FILE32API) | 
|---|
|  | 50 | #define fopen64 fopen | 
|---|
|  | 51 | #define ftello64 ftell | 
|---|
|  | 52 | #define fseeko64 fseek | 
|---|
|  | 53 | #else | 
|---|
|  | 54 | #ifdef _MSC_VER | 
|---|
|  | 55 | #define fopen64 fopen | 
|---|
|  | 56 | #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) | 
|---|
|  | 57 | #define ftello64 _ftelli64 | 
|---|
|  | 58 | #define fseeko64 _fseeki64 | 
|---|
|  | 59 | #else // old MSC | 
|---|
|  | 60 | #define ftello64 ftell | 
|---|
|  | 61 | #define fseeko64 fseek | 
|---|
|  | 62 | #endif | 
|---|
|  | 63 | #endif | 
|---|
|  | 64 | #endif | 
|---|
|  | 65 |  | 
|---|
|  | 66 | /* | 
|---|
|  | 67 | #ifndef ZPOS64_T | 
|---|
|  | 68 | #ifdef _WIN32 | 
|---|
|  | 69 | #define ZPOS64_T fpos_t | 
|---|
|  | 70 | #else | 
|---|
|  | 71 | #include <stdint.h> | 
|---|
|  | 72 | #define ZPOS64_T uint64_t | 
|---|
|  | 73 | #endif | 
|---|
|  | 74 | #endif | 
|---|
|  | 75 | */ | 
|---|
|  | 76 |  | 
|---|
|  | 77 | #ifdef HAVE_MINIZIP64_CONF_H | 
|---|
|  | 78 | #include "mz64conf.h" | 
|---|
|  | 79 | #endif | 
|---|
|  | 80 |  | 
|---|
|  | 81 | /* a type choosen by DEFINE */ | 
|---|
|  | 82 | #ifdef HAVE_64BIT_INT_CUSTOM | 
|---|
|  | 83 | typedef  64BIT_INT_CUSTOM_TYPE ZPOS64_T; | 
|---|
|  | 84 | #else | 
|---|
|  | 85 | #ifdef HAS_STDINT_H | 
|---|
|  | 86 | #include "stdint.h" | 
|---|
|  | 87 | typedef uint64_t ZPOS64_T; | 
|---|
|  | 88 | #else | 
|---|
|  | 89 |  | 
|---|
|  | 90 |  | 
|---|
|  | 91 | #if defined(_MSC_VER) || defined(__BORLANDC__) | 
|---|
|  | 92 | typedef unsigned __int64 ZPOS64_T; | 
|---|
|  | 93 | #else | 
|---|
|  | 94 | typedef unsigned long long int ZPOS64_T; | 
|---|
|  | 95 | #endif | 
|---|
|  | 96 | #endif | 
|---|
|  | 97 | #endif | 
|---|
|  | 98 |  | 
|---|
|  | 99 |  | 
|---|
|  | 100 |  | 
|---|
|  | 101 | #ifdef __cplusplus | 
|---|
|  | 102 | extern "C" { | 
|---|
|  | 103 | #endif | 
|---|
|  | 104 |  | 
|---|
|  | 105 | #ifndef OF | 
|---|
|  | 106 | #define OF _Z_OF | 
|---|
|  | 107 | #endif | 
|---|
|  | 108 |  | 
|---|
|  | 109 | #define ZLIB_FILEFUNC_SEEK_CUR (1) | 
|---|
|  | 110 | #define ZLIB_FILEFUNC_SEEK_END (2) | 
|---|
|  | 111 | #define ZLIB_FILEFUNC_SEEK_SET (0) | 
|---|
|  | 112 |  | 
|---|
|  | 113 | #define ZLIB_FILEFUNC_MODE_READ      (1) | 
|---|
|  | 114 | #define ZLIB_FILEFUNC_MODE_WRITE     (2) | 
|---|
|  | 115 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) | 
|---|
|  | 116 |  | 
|---|
|  | 117 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) | 
|---|
|  | 118 | #define ZLIB_FILEFUNC_MODE_CREATE   (8) | 
|---|
|  | 119 |  | 
|---|
|  | 120 |  | 
|---|
|  | 121 | #ifndef ZCALLBACK | 
|---|
|  | 122 | #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) | 
|---|
|  | 123 | #define ZCALLBACK CALLBACK | 
|---|
|  | 124 | #else | 
|---|
|  | 125 | #define ZCALLBACK | 
|---|
|  | 126 | #endif | 
|---|
|  | 127 | #endif | 
|---|
|  | 128 |  | 
|---|
|  | 129 |  | 
|---|
|  | 130 |  | 
|---|
|  | 131 |  | 
|---|
|  | 132 | typedef voidpf   (ZCALLBACK *open_file_func)      OF((voidpf opaque, voidpf file, int mode)); | 
|---|
|  | 133 | typedef uLong    (ZCALLBACK *read_file_func)      OF((voidpf opaque, voidpf stream, void* buf, uLong size)); | 
|---|
|  | 134 | typedef uLong    (ZCALLBACK *write_file_func)     OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); | 
|---|
|  | 135 | typedef int      (ZCALLBACK *close_file_func)     OF((voidpf opaque, voidpf stream)); | 
|---|
|  | 136 | typedef int      (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); | 
|---|
|  | 137 |  | 
|---|
|  | 138 | typedef uLong     (ZCALLBACK *tell_file_func)      OF((voidpf opaque, voidpf stream)); | 
|---|
|  | 139 | typedef int     (ZCALLBACK *seek_file_func)      OF((voidpf opaque, voidpf stream, uLong offset, int origin)); | 
|---|
|  | 140 |  | 
|---|
|  | 141 |  | 
|---|
|  | 142 | /* here is the "old" 32 bits structure structure */ | 
|---|
|  | 143 | typedef struct zlib_filefunc_def_s | 
|---|
|  | 144 | { | 
|---|
|  | 145 | open_file_func      zopen_file; | 
|---|
|  | 146 | read_file_func      zread_file; | 
|---|
|  | 147 | write_file_func     zwrite_file; | 
|---|
|  | 148 | tell_file_func      ztell_file; | 
|---|
|  | 149 | seek_file_func      zseek_file; | 
|---|
|  | 150 | close_file_func     zclose_file; | 
|---|
|  | 151 | testerror_file_func zerror_file; | 
|---|
|  | 152 | voidpf              opaque; | 
|---|
|  | 153 | } zlib_filefunc_def; | 
|---|
|  | 154 |  | 
|---|
|  | 155 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func)    OF((voidpf opaque, voidpf stream)); | 
|---|
|  | 156 | typedef int     (ZCALLBACK *seek64_file_func)    OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); | 
|---|
|  | 157 | typedef voidpf   (ZCALLBACK *open64_file_func)    OF((voidpf opaque, voidpf file, int mode)); | 
|---|
|  | 158 |  | 
|---|
|  | 159 | typedef struct zlib_filefunc64_def_s | 
|---|
|  | 160 | { | 
|---|
|  | 161 | open64_file_func    zopen64_file; | 
|---|
|  | 162 | read_file_func      zread_file; | 
|---|
|  | 163 | write_file_func     zwrite_file; | 
|---|
|  | 164 | tell64_file_func    ztell64_file; | 
|---|
|  | 165 | seek64_file_func    zseek64_file; | 
|---|
|  | 166 | close_file_func     zclose_file; | 
|---|
|  | 167 | testerror_file_func zerror_file; | 
|---|
|  | 168 | voidpf              opaque; | 
|---|
|  | 169 | close_file_func     zfakeclose_file; // for no-auto-close flag | 
|---|
|  | 170 | } zlib_filefunc64_def; | 
|---|
|  | 171 |  | 
|---|
|  | 172 | void fill_qiodevice64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); | 
|---|
|  | 173 | void fill_qiodevice_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); | 
|---|
|  | 174 |  | 
|---|
|  | 175 | /* now internal definition, only for zip.c and unzip.h */ | 
|---|
|  | 176 | typedef struct zlib_filefunc64_32_def_s | 
|---|
|  | 177 | { | 
|---|
|  | 178 | zlib_filefunc64_def zfile_func64; | 
|---|
|  | 179 | open_file_func      zopen32_file; | 
|---|
|  | 180 | tell_file_func      ztell32_file; | 
|---|
|  | 181 | seek_file_func      zseek32_file; | 
|---|
|  | 182 | } zlib_filefunc64_32_def; | 
|---|
|  | 183 |  | 
|---|
|  | 184 |  | 
|---|
|  | 185 | #define ZREAD64(filefunc,filestream,buf,size)     ((*((filefunc).zfile_func64.zread_file))   ((filefunc).zfile_func64.opaque,filestream,buf,size)) | 
|---|
|  | 186 | #define ZWRITE64(filefunc,filestream,buf,size)    ((*((filefunc).zfile_func64.zwrite_file))  ((filefunc).zfile_func64.opaque,filestream,buf,size)) | 
|---|
|  | 187 | //#define ZTELL64(filefunc,filestream)            ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) | 
|---|
|  | 188 | //#define ZSEEK64(filefunc,filestream,pos,mode)   ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) | 
|---|
|  | 189 | #define ZCLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zclose_file))  ((filefunc).zfile_func64.opaque,filestream)) | 
|---|
|  | 190 | #define ZFAKECLOSE64(filefunc,filestream)             ((*((filefunc).zfile_func64.zfakeclose_file))  ((filefunc).zfile_func64.opaque,filestream)) | 
|---|
|  | 191 | #define ZERROR64(filefunc,filestream)             ((*((filefunc).zfile_func64.zerror_file))  ((filefunc).zfile_func64.opaque,filestream)) | 
|---|
|  | 192 |  | 
|---|
|  | 193 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf file,int mode)); | 
|---|
|  | 194 | int    call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); | 
|---|
|  | 195 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); | 
|---|
|  | 196 |  | 
|---|
|  | 197 | void    fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); | 
|---|
|  | 198 |  | 
|---|
|  | 199 | #define ZOPEN64(filefunc,filename,mode)         (call_zopen64((&(filefunc)),(filename),(mode))) | 
|---|
|  | 200 | #define ZTELL64(filefunc,filestream)            (call_ztell64((&(filefunc)),(filestream))) | 
|---|
|  | 201 | #define ZSEEK64(filefunc,filestream,pos,mode)   (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) | 
|---|
|  | 202 |  | 
|---|
|  | 203 | #ifdef __cplusplus | 
|---|
|  | 204 | } | 
|---|
|  | 205 | #endif | 
|---|
|  | 206 |  | 
|---|
|  | 207 | #endif | 
|---|