ioapi.h 5.9 KB

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