ioapi.h 7.8 KB

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