ioapi.h 7.0 KB

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