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 For more info read MiniZip_info.txt 10 11 Changes 12 13 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) 14 Oct-2009 - Change to fseeko64, ftello64 and fopen64 so large files would work on linux. 15 More if/def section may be needed to support other platforms 16 Oct-2009 - Defined fxxxx64 calls to normal fopen/ftell/fseek so they would compile on windows. 17 (but you should use iowin32.c for windows instead) 18 19 */ 20 21 #ifndef _ZLIBIOAPI64_H 22 #define _ZLIBIOAPI64_H 23 24 #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 25 26 // Linux needs this to support file operation on files larger then 4+GB 27 // But might need better if/def to select just the platforms that needs them. 28 29 #ifndef __USE_FILE_OFFSET64 30 #define __USE_FILE_OFFSET64 31 #endif 32 #ifndef __USE_LARGEFILE64 33 #define __USE_LARGEFILE64 34 #endif 35 #ifndef _LARGEFILE64_SOURCE 36 #define _LARGEFILE64_SOURCE 37 #endif 38 #ifndef _FILE_OFFSET_BIT 39 #define _FILE_OFFSET_BIT 64 40 #endif 41 42 #endif 43 44 #include <stdio.h> 45 #include <stdlib.h> 46 #include "zlib.h" 47 48 /* GODOT start */ 49 /* Mighty Gentoo saves the day by breaking the API of their zlib.h, 50 * removing this definition of OF(args) for no practical reason 51 * worth breaking compatibility with all projects that embed minizip 52 * while trying not to diverge too much from upstream zlib. 53 * Cf. https://github.com/godotengine/godot/issues/10539 54 * 55 * "By and large, this is good open source behaviour, and fits with 56 * the gentoo _don't fuck with upstream's releases_ philosophy" 57 * -- Gentoo philosopher 58 */ 59 #ifndef OF /* function prototypes */ 60 #define OF(args) args 61 #endif 62 /* GODOT end */ 63 64 #if defined(USE_FILE32API) 65 #define fopen64 fopen 66 #define ftello64 ftell 67 #define fseeko64 fseek 68 #else 69 #ifdef __FreeBSD__ 70 #define fopen64 fopen 71 #define ftello64 ftello 72 #define fseeko64 fseeko 73 #endif 74 #ifdef _MSC_VER 75 #define fopen64 fopen 76 #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 77 #define ftello64 _ftelli64 78 #define fseeko64 _fseeki64 79 #else // old MSC 80 #define ftello64 ftell 81 #define fseeko64 fseek 82 #endif 83 #endif 84 #endif 85 86 /* 87 #ifndef ZPOS64_T 88 #ifdef _WIN32 89 #define ZPOS64_T fpos_t 90 #else 91 #include <stdint.h> 92 #define ZPOS64_T uint64_t 93 #endif 94 #endif 95 */ 96 97 #ifdef HAVE_MINIZIP64_CONF_H 98 #include "mz64conf.h" 99 #endif 100 101 /* a type choosen by DEFINE */ 102 #ifdef HAVE_64BIT_INT_CUSTOM 103 typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 104 #else 105 #ifdef HAS_STDINT_H 106 #include "stdint.h" 107 typedef uint64_t ZPOS64_T; 108 #else 109 110 /* Maximum unsigned 32-bit value used as placeholder for zip64 */ 111 #define MAXU32 0xffffffff 112 113 #if defined(_MSC_VER) || defined(__BORLANDC__) 114 typedef unsigned __int64 ZPOS64_T; 115 #else 116 typedef unsigned long long int ZPOS64_T; 117 #endif 118 #endif 119 #endif 120 121 122 123 #ifdef __cplusplus 124 extern "C" { 125 #endif 126 127 128 #define ZLIB_FILEFUNC_SEEK_CUR (1) 129 #define ZLIB_FILEFUNC_SEEK_END (2) 130 #define ZLIB_FILEFUNC_SEEK_SET (0) 131 132 #define ZLIB_FILEFUNC_MODE_READ (1) 133 #define ZLIB_FILEFUNC_MODE_WRITE (2) 134 #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 135 136 #define ZLIB_FILEFUNC_MODE_EXISTING (4) 137 #define ZLIB_FILEFUNC_MODE_CREATE (8) 138 139 140 #ifndef ZCALLBACK 141 #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 142 #define ZCALLBACK CALLBACK 143 #else 144 #define ZCALLBACK 145 #endif 146 #endif 147 148 149 150 151 typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 152 typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 153 typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 154 typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 155 typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 156 157 typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 158 typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 159 160 161 /* here is the "old" 32 bits structure structure */ 162 typedef struct zlib_filefunc_def_s 163 { 164 open_file_func zopen_file; 165 read_file_func zread_file; 166 write_file_func zwrite_file; 167 tell_file_func ztell_file; 168 seek_file_func zseek_file; 169 close_file_func zclose_file; 170 testerror_file_func zerror_file; 171 voidpf opaque; 172 /* GODOT start */ 173 alloc_func alloc_mem; 174 free_func free_mem; 175 /* GODOT end */ 176 } zlib_filefunc_def; 177 178 typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 179 typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 180 typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 181 182 typedef struct zlib_filefunc64_def_s 183 { 184 open64_file_func zopen64_file; 185 read_file_func zread_file; 186 write_file_func zwrite_file; 187 tell64_file_func ztell64_file; 188 seek64_file_func zseek64_file; 189 close_file_func zclose_file; 190 testerror_file_func zerror_file; 191 voidpf opaque; 192 /* GODOT start */ 193 alloc_func alloc_mem; 194 free_func free_mem; 195 /* GODOT end */ 196 } zlib_filefunc64_def; 197 198 void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 199 void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 200 201 /* now internal definition, only for zip.c and unzip.h */ 202 typedef struct zlib_filefunc64_32_def_s 203 { 204 zlib_filefunc64_def zfile_func64; 205 open_file_func zopen32_file; 206 tell_file_func ztell32_file; 207 seek_file_func zseek32_file; 208 } zlib_filefunc64_32_def; 209 210 211 #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 212 #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 213 //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream)) 214 //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode)) 215 #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 216 #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 217 218 voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 219 long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 220 ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 221 222 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32); 223 224 #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 225 #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 226 #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 227 228 #ifdef __cplusplus 229 } 230 #endif 231 232 #endif 233