1 /* ioapi.h -- IO base function header for compress/uncompress .zip
2 part of the MiniZip project
4 Copyright (C) 2012-2017 Nathan Moinvaziri
5 https://github.com/nmoinvaz/minizip
6 Copyright (C) 2009-2010 Mathias Svensson
7 Modifications for Zip64 support
9 Copyright (C) 1998-2010 Gilles Vollant
10 http://www.winimage.com/zLibDll/minizip.html
12 This program is distributed under the terms of the same license as zlib.
13 See the accompanying LICENSE file for the full text of the license.
16 #ifndef _ZLIBIOAPI64_H
17 #define _ZLIBIOAPI64_H
26 # define ZIP_UNUSED __attribute__((__unused__))
31 #if defined(USE_FILE32API)
32 # define fopen64 fopen
33 # define ftello64 ftell
34 # define fseeko64 fseek
36 # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) || defined(__APPLE__) || defined(__ANDROID__) || defined(__linux__) || defined(__EMSCRIPTEN__)
37 # define fopen64 fopen
38 # define ftello64 ftello
39 # define fseeko64 fseeko
42 # define fopen64 fopen
43 # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC)))
44 # define ftello64 _ftelli64
45 # define fseeko64 _fseeki64
47 # define ftello64 ftell
48 # define fseeko64 fseek
57 #define ZLIB_FILEFUNC_SEEK_CUR (1)
58 #define ZLIB_FILEFUNC_SEEK_END (2)
59 #define ZLIB_FILEFUNC_SEEK_SET (0)
61 #define ZLIB_FILEFUNC_MODE_READ (1)
62 #define ZLIB_FILEFUNC_MODE_WRITE (2)
63 #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
64 #define ZLIB_FILEFUNC_MODE_EXISTING (4)
65 #define ZLIB_FILEFUNC_MODE_CREATE (8)
68 # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \
69 defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
70 # define ZCALLBACK CALLBACK
76 typedef voidpf (ZCALLBACK *open_file_func) (voidpf opaque, const char *filename, int mode);
77 typedef voidpf (ZCALLBACK *opendisk_file_func) (voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
78 typedef uint32_t (ZCALLBACK *read_file_func) (voidpf opaque, voidpf stream, void* buf, uint32_t size);
79 typedef uint32_t (ZCALLBACK *write_file_func) (voidpf opaque, voidpf stream, const void *buf, uint32_t size);
80 typedef int (ZCALLBACK *close_file_func) (voidpf opaque, voidpf stream);
81 typedef int (ZCALLBACK *error_file_func) (voidpf opaque, voidpf stream);
83 typedef long (ZCALLBACK *tell_file_func) (voidpf opaque, voidpf stream);
84 typedef long (ZCALLBACK *seek_file_func) (voidpf opaque, voidpf stream, uint32_t offset, int origin);
86 /* here is the "old" 32 bits structure structure */
87 typedef struct zlib_filefunc_def_s
89 open_file_func zopen_file;
90 opendisk_file_func zopendisk_file;
91 read_file_func zread_file;
92 write_file_func zwrite_file;
93 tell_file_func ztell_file;
94 seek_file_func zseek_file;
95 close_file_func zclose_file;
96 error_file_func zerror_file;
100 typedef uint64_t (ZCALLBACK *tell64_file_func) (voidpf opaque, voidpf stream);
101 typedef long (ZCALLBACK *seek64_file_func) (voidpf opaque, voidpf stream, uint64_t offset, int origin);
102 typedef voidpf (ZCALLBACK *open64_file_func) (voidpf opaque, const void *filename, int mode);
103 typedef voidpf (ZCALLBACK *opendisk64_file_func)(voidpf opaque, voidpf stream, uint32_t number_disk, int mode);
105 typedef struct zlib_filefunc64_def_s
107 open64_file_func zopen64_file;
108 opendisk64_file_func zopendisk64_file;
109 read_file_func zread_file;
110 write_file_func zwrite_file;
111 tell64_file_func ztell64_file;
112 seek64_file_func zseek64_file;
113 close_file_func zclose_file;
114 error_file_func zerror_file;
116 } zlib_filefunc64_def;
118 void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def);
119 void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def);
121 /* now internal definition, only for zip.c and unzip.h */
122 typedef struct zlib_filefunc64_32_def_s
124 zlib_filefunc64_def zfile_func64;
125 open_file_func zopen32_file;
126 opendisk_file_func zopendisk32_file;
127 tell_file_func ztell32_file;
128 seek_file_func zseek32_file;
129 } zlib_filefunc64_32_def;
131 #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
132 #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size))
133 /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/
134 /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/
135 #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream))
136 #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream))
138 voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc,const void*filename, int mode);
139 voidpf call_zopendisk64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint32_t number_disk, int mode);
140 long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, uint64_t offset, int origin);
141 uint64_t call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream);
143 void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32);
145 #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode)))
146 #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode)))
147 #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream)))
148 #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode)))