ioapi.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /* ioapi.h -- IO base function header for compress/uncompress .zip
  2. part of the MiniZip project
  3. Copyright (C) 2012-2017 Nathan Moinvaziri
  4. https://github.com/nmoinvaz/minizip
  5. Copyright (C) 2009-2010 Mathias Svensson
  6. Modifications for Zip64 support
  7. http://result42.com
  8. Copyright (C) 1998-2010 Gilles Vollant
  9. http://www.winimage.com/zLibDll/minizip.html
  10. This program is distributed under the terms of the same license as zlib.
  11. See the accompanying LICENSE file for the full text of the license.
  12. */
  13. #ifndef _ZLIBIOAPI64_H
  14. #define _ZLIBIOAPI64_H
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <stdint.h>
  18. #include "zlib.h"
  19. #ifdef __GNUC__
  20. # define ZIP_UNUSED __attribute__((__unused__))
  21. #else
  22. # define ZIP_UNUSED
  23. #endif
  24. #if defined(USE_FILE32API)
  25. # define fopen64 fopen
  26. # define ftello64 ftell
  27. # define fseeko64 fseek
  28. #else
  29. # if defined(_MSC_VER)
  30. # define fopen64 fopen
  31. # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
  32. # define ftello64 _ftelli64
  33. # define fseeko64 _fseeki64
  34. # else /* old MSC */
  35. # define ftello64 ftell
  36. # define fseeko64 fseek
  37. # endif
  38. # else
  39. # define fopen64 fopen
  40. # define ftello64 ftello
  41. # define fseeko64 fseeko
  42. # endif
  43. #endif
  44. #ifdef __cplusplus
  45. extern "C" {
  46. #endif
  47. #define ZLIB_FILEFUNC_SEEK_CUR (1)
  48. #define ZLIB_FILEFUNC_SEEK_END (2)
  49. #define ZLIB_FILEFUNC_SEEK_SET (0)
  50. #define ZLIB_FILEFUNC_MODE_READ (1)
  51. #define ZLIB_FILEFUNC_MODE_WRITE (2)
  52. #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
  53. #define ZLIB_FILEFUNC_MODE_EXISTING (4)
  54. #define ZLIB_FILEFUNC_MODE_CREATE (8)
  55. #ifndef ZCALLBACK
  56. # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \
  57. defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
  58. # define ZCALLBACK CALLBACK
  59. # else
  60. # define ZCALLBACK
  61. # endif
  62. #endif
  63. #define UINT8_MAX 255
  64. #define UINT16_MAX 65535
  65. #define UINT32_MAX 4294967295U
  66. #define UINT64_MAX 18446744073709551615ULL
  67. typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char *filename, int mode);
  68. typedef voidpf (ZCALLBACK *opendisk_file_func) (voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
  69. typedef uint32_t (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uint32_t size);
  70. typedef uint32_t (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void *buf, uint32_t size);
  71. typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
  72. typedef int (ZCALLBACK *error_file_func) (voidpf opaque, voidpf stream);
  73. typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
  74. typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uint32_t offset, int origin);
  75. /* here is the "old" 32 bits structure structure */
  76. typedef struct zlib_filefunc_def_s
  77. {
  78. open_file_func zopen_file;
  79. opendisk_file_func zopendisk_file;
  80. read_file_func zread_file;
  81. write_file_func zwrite_file;
  82. tell_file_func ztell_file;
  83. seek_file_func zseek_file;
  84. close_file_func zclose_file;
  85. error_file_func zerror_file;
  86. voidpf opaque;
  87. } zlib_filefunc_def;
  88. typedef uint64_t (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
  89. typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, uint64_t offset, int origin);
  90. typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void *filename, int mode);
  91. typedef voidpf (ZCALLBACK *opendisk64_file_func)(voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
  92. typedef struct zlib_filefunc64_def_s
  93. {
  94. open64_file_func zopen64_file;
  95. opendisk64_file_func zopendisk64_file;
  96. read_file_func zread_file;
  97. write_file_func zwrite_file;
  98. tell64_file_func ztell64_file;
  99. seek64_file_func zseek64_file;
  100. close_file_func zclose_file;
  101. error_file_func zerror_file;
  102. voidpf opaque;
  103. } zlib_filefunc64_def;
  104. void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
  105. void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
  106. /* now internal definition, only for zip.c and unzip.h */
  107. typedef struct zlib_filefunc64_32_def_s
  108. {
  109. zlib_filefunc64_def zfile_func64;
  110. open_file_func zopen32_file;
  111. opendisk_file_func zopendisk32_file;
  112. tell_file_func ztell32_file;
  113. seek_file_func zseek32_file;
  114. } zlib_filefunc64_32_def;
  115. #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
  116. #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
  117. /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/
  118. /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/
  119. #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
  120. #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
  121. voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc,const void*filename, int mode);
  122. voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode);
  123. long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin);
  124. uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream);
  125. void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32);
  126. #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
  127. #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode)))
  128. #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
  129. #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))
  130. #ifdef __cplusplus
  131. }
  132. #endif
  133. #endif