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