ioapi.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #ifndef OF /* function prototypes */
  17. # ifdef STDC
  18. # define OF(args) args
  19. # else
  20. # define OF(args) ()
  21. # endif
  22. #endif
  23. #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__))
  24. // Linux needs this to support file operation on files larger then 4+GB
  25. // But might need better if/def to select just the platforms that needs them.
  26. #ifndef __USE_FILE_OFFSET64
  27. #define __USE_FILE_OFFSET64
  28. #endif
  29. #ifndef __USE_LARGEFILE64
  30. #define __USE_LARGEFILE64
  31. #endif
  32. #ifndef _LARGEFILE64_SOURCE
  33. #define _LARGEFILE64_SOURCE
  34. #endif
  35. #ifndef _FILE_OFFSET_BIT
  36. #define _FILE_OFFSET_BIT 64
  37. #endif
  38. #endif
  39. #include <stdio.h>
  40. #include <stdlib.h>
  41. #include "zlib.h"
  42. #if defined(USE_FILE32API)
  43. #define fopen64 fopen
  44. #define ftello64 ftell
  45. #define fseeko64 fseek
  46. #else
  47. #ifdef __FreeBSD__
  48. #define fopen64 fopen
  49. #define ftello64 ftello
  50. #define fseeko64 fseeko
  51. #endif
  52. #ifdef _MSC_VER
  53. #define fopen64 fopen
  54. #if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
  55. #define ftello64 _ftelli64
  56. #define fseeko64 _fseeki64
  57. #else // old MSC
  58. #define ftello64 ftell
  59. #define fseeko64 fseek
  60. #endif
  61. #endif
  62. #endif
  63. #ifndef ZPOS64_T
  64. #ifdef _WIN32
  65. #define ZPOS64_T fpos_t
  66. #else
  67. #include <stdint.h>
  68. #define ZPOS64_T uint64_t
  69. #endif
  70. #endif
  71. #ifdef HAVE_MINIZIP64_CONF_H
  72. #include "mz64conf.h"
  73. #endif
  74. /* a type chosen by DEFINE */
  75. #ifdef HAVE_64BIT_INT_CUSTOM
  76. typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T;
  77. #else
  78. #ifdef HAS_STDINT_H
  79. #include "stdint.h"
  80. typedef uint64_t ZPOS64_T;
  81. #else
  82. /* Maximum unsigned 32-bit value used as placeholder for zip64 */
  83. #define MAXU32 0xffffffff
  84. //#if defined(_MSC_VER) || defined(__BORLANDC__)
  85. // typedef unsigned __int64 ZPOS64_T;
  86. //#else
  87. // typedef unsigned long long int ZPOS64_T;
  88. //#endif
  89. #endif
  90. #endif
  91. #if defined(_MSC_VER)
  92. #pragma warning (push)
  93. #pragma warning (disable : 4005)
  94. /* If building or using zlib as a DLL, define ZLIB_DLL.
  95. * This is not mandatory, but it offers a little performance increase.
  96. */
  97. # ifdef ZLIB_DLL
  98. # ifdef ZLIB_INTERNAL
  99. # define ZEXPORT __declspec(dllexport)
  100. # else
  101. # define ZEXPORT __declspec(dllimport)
  102. # endif
  103. # endif /* ZLIB_DLL */
  104. #pragma warning (pop)
  105. #ifdef MINIZIP_DLL
  106. #define MINIZIP_EXPORT __declspec(dllexport)
  107. #else
  108. #define MINIZIP_EXPORT __declspec(dllimport)
  109. #endif
  110. #else //not MSVC
  111. #define MINIZIP_EXPORT
  112. #endif
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. #define ZLIB_FILEFUNC_SEEK_CUR (1)
  117. #define ZLIB_FILEFUNC_SEEK_END (2)
  118. #define ZLIB_FILEFUNC_SEEK_SET (0)
  119. #define ZLIB_FILEFUNC_MODE_READ (1)
  120. #define ZLIB_FILEFUNC_MODE_WRITE (2)
  121. #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
  122. #define ZLIB_FILEFUNC_MODE_EXISTING (4)
  123. #define ZLIB_FILEFUNC_MODE_CREATE (8)
  124. #ifndef ZCALLBACK
  125. #if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
  126. #define ZCALLBACK CALLBACK
  127. #else
  128. #define ZCALLBACK
  129. #endif
  130. #endif
  131. typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
  132. typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
  133. typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
  134. typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
  135. typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
  136. typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
  137. typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin));
  138. /* here is the "old" 32 bits structure structure */
  139. typedef struct zlib_filefunc_def_s
  140. {
  141. open_file_func zopen_file;
  142. read_file_func zread_file;
  143. write_file_func zwrite_file;
  144. tell_file_func ztell_file;
  145. seek_file_func zseek_file;
  146. close_file_func zclose_file;
  147. testerror_file_func zerror_file;
  148. voidpf opaque;
  149. } zlib_filefunc_def;
  150. typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream));
  151. typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
  152. typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode));
  153. typedef struct zlib_filefunc64_def_s
  154. {
  155. open64_file_func zopen64_file;
  156. read_file_func zread_file;
  157. write_file_func zwrite_file;
  158. tell64_file_func ztell64_file;
  159. seek64_file_func zseek64_file;
  160. close_file_func zclose_file;
  161. testerror_file_func zerror_file;
  162. voidpf opaque;
  163. } zlib_filefunc64_def;
  164. void MINIZIP_EXPORT fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def));
  165. void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
  166. /* now internal definition, only for zip.c and unzip.h */
  167. typedef struct zlib_filefunc64_32_def_s
  168. {
  169. zlib_filefunc64_def zfile_func64;
  170. open_file_func zopen32_file;
  171. tell_file_func ztell32_file;
  172. seek_file_func zseek32_file;
  173. } zlib_filefunc64_32_def;
  174. #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
  175. #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
  176. //#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))
  177. //#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))
  178. #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
  179. #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
  180. voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode));
  181. long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin));
  182. ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream));
  183. void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32);
  184. #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
  185. #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
  186. #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
  187. #ifdef __cplusplus
  188. }
  189. #endif
  190. #endif