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