ioapi.h 6.7 KB

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