Visualization Library 2.0.0-b5

A lightweight C++ OpenGL middleware for 2D/3D graphics

VL     Star     Watch     Fork     Issue

[Download] [Tutorials] [All Classes] [Grouped Classes]
ioapi.c
Go to the documentation of this file.
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 */
12 
13 #if defined(_WIN32) && (!(defined(_CRT_SECURE_NO_WARNINGS)))
14  #define _CRT_SECURE_NO_WARNINGS
15 #endif
16 
17 #if defined(__APPLE__) || defined(IOAPI_NO_64)
18 // In darwin and perhaps other BSD variants off_t is a 64 bit value, hence no need for specific 64 bit functions
19 #define FOPEN_FUNC(filename, mode) fopen(filename, mode)
20 #define FTELLO_FUNC(stream) ftello(stream)
21 #define FSEEKO_FUNC(stream, offset, origin) fseeko(stream, offset, origin)
22 #else
23 #define FOPEN_FUNC(filename, mode) fopen64(filename, mode)
24 #define FTELLO_FUNC(stream) ftello64(stream)
25 #define FSEEKO_FUNC(stream, offset, origin) fseeko64(stream, offset, origin)
26 #endif
27 
28 
29 #include "ioapi.h"
30 
31 voidpf call_zopen64 (const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)
32 {
33  if (pfilefunc->zfile_func64.zopen64_file != NULL)
34  return (*(pfilefunc->zfile_func64.zopen64_file)) (pfilefunc->zfile_func64.opaque,filename,mode);
35  else
36  {
37  return (*(pfilefunc->zopen32_file))(pfilefunc->zfile_func64.opaque,(const char*)filename,mode);
38  }
39 }
40 
41 long call_zseek64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)
42 {
43  if (pfilefunc->zfile_func64.zseek64_file != NULL)
44  return (*(pfilefunc->zfile_func64.zseek64_file)) (pfilefunc->zfile_func64.opaque,filestream,offset,origin);
45  else
46  {
47  uLong offsetTruncated = (uLong)offset;
48  if (offsetTruncated != offset)
49  return -1;
50  else
51  return (*(pfilefunc->zseek32_file))(pfilefunc->zfile_func64.opaque,filestream,offsetTruncated,origin);
52  }
53 }
54 
55 ZPOS64_T call_ztell64 (const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)
56 {
57  if (pfilefunc->zfile_func64.zseek64_file != NULL)
58  return (*(pfilefunc->zfile_func64.ztell64_file)) (pfilefunc->zfile_func64.opaque,filestream);
59  else
60  {
61  uLong tell_uLong = (*(pfilefunc->ztell32_file))(pfilefunc->zfile_func64.opaque,filestream);
62  if ((tell_uLong) == MAXU32)
63  return (ZPOS64_T)-1;
64  else
65  return tell_uLong;
66  }
67 }
68 
70 {
71  p_filefunc64_32->zfile_func64.zopen64_file = NULL;
72  p_filefunc64_32->zopen32_file = p_filefunc32->zopen_file;
73  p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
74  p_filefunc64_32->zfile_func64.zread_file = p_filefunc32->zread_file;
75  p_filefunc64_32->zfile_func64.zwrite_file = p_filefunc32->zwrite_file;
76  p_filefunc64_32->zfile_func64.ztell64_file = NULL;
77  p_filefunc64_32->zfile_func64.zseek64_file = NULL;
78  p_filefunc64_32->zfile_func64.zclose_file = p_filefunc32->zclose_file;
79  p_filefunc64_32->zfile_func64.zerror_file = p_filefunc32->zerror_file;
80  p_filefunc64_32->zfile_func64.opaque = p_filefunc32->opaque;
81  p_filefunc64_32->zseek32_file = p_filefunc32->zseek_file;
82  p_filefunc64_32->ztell32_file = p_filefunc32->ztell_file;
83 }
84 
85 
86 
87 static voidpf ZCALLBACK fopen_file_func OF((voidpf opaque, const char* filename, int mode));
88 static uLong ZCALLBACK fread_file_func OF((voidpf opaque, voidpf stream, void* buf, uLong size));
89 static uLong ZCALLBACK fwrite_file_func OF((voidpf opaque, voidpf stream, const void* buf,uLong size));
90 static ZPOS64_T ZCALLBACK ftell64_file_func OF((voidpf opaque, voidpf stream));
91 static long ZCALLBACK fseek64_file_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin));
92 static int ZCALLBACK fclose_file_func OF((voidpf opaque, voidpf stream));
93 static int ZCALLBACK ferror_file_func OF((voidpf opaque, voidpf stream));
94 
95 static voidpf ZCALLBACK fopen_file_func (voidpf opaque, const char* filename, int mode)
96 {
97  FILE* file = NULL;
98  const char* mode_fopen = NULL;
100  mode_fopen = "rb";
101  else
102  if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
103  mode_fopen = "r+b";
104  else
105  if (mode & ZLIB_FILEFUNC_MODE_CREATE)
106  mode_fopen = "wb";
107 
108  if ((filename!=NULL) && (mode_fopen != NULL))
109  file = fopen(filename, mode_fopen);
110  return file;
111 }
112 
113 static voidpf ZCALLBACK fopen64_file_func (voidpf opaque, const void* filename, int mode)
114 {
115  FILE* file = NULL;
116  const char* mode_fopen = NULL;
118  mode_fopen = "rb";
119  else
120  if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
121  mode_fopen = "r+b";
122  else
123  if (mode & ZLIB_FILEFUNC_MODE_CREATE)
124  mode_fopen = "wb";
125 
126  if ((filename!=NULL) && (mode_fopen != NULL))
127  file = FOPEN_FUNC((const char*)filename, mode_fopen);
128  return file;
129 }
130 
131 
132 static uLong ZCALLBACK fread_file_func (voidpf opaque, voidpf stream, void* buf, uLong size)
133 {
134  uLong ret;
135  ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
136  return ret;
137 }
138 
139 static uLong ZCALLBACK fwrite_file_func (voidpf opaque, voidpf stream, const void* buf, uLong size)
140 {
141  uLong ret;
142  ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
143  return ret;
144 }
145 
146 static long ZCALLBACK ftell_file_func (voidpf opaque, voidpf stream)
147 {
148  long ret;
149  ret = ftell((FILE *)stream);
150  return ret;
151 }
152 
153 
154 static ZPOS64_T ZCALLBACK ftell64_file_func (voidpf opaque, voidpf stream)
155 {
156  ZPOS64_T ret;
157  ret = FTELLO_FUNC((FILE *)stream);
158  return ret;
159 }
160 
161 static long ZCALLBACK fseek_file_func (voidpf opaque, voidpf stream, uLong offset, int origin)
162 {
163  int fseek_origin=0;
164  long ret;
165  switch (origin)
166  {
168  fseek_origin = SEEK_CUR;
169  break;
171  fseek_origin = SEEK_END;
172  break;
174  fseek_origin = SEEK_SET;
175  break;
176  default: return -1;
177  }
178  ret = 0;
179  if (fseek((FILE *)stream, offset, fseek_origin) != 0)
180  ret = -1;
181  return ret;
182 }
183 
184 static long ZCALLBACK fseek64_file_func (voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)
185 {
186  int fseek_origin=0;
187  long ret;
188  switch (origin)
189  {
191  fseek_origin = SEEK_CUR;
192  break;
194  fseek_origin = SEEK_END;
195  break;
197  fseek_origin = SEEK_SET;
198  break;
199  default: return -1;
200  }
201  ret = 0;
202 
203  if(FSEEKO_FUNC((FILE *)stream, offset, fseek_origin) != 0)
204  ret = -1;
205 
206  return ret;
207 }
208 
209 
210 static int ZCALLBACK fclose_file_func (voidpf opaque, voidpf stream)
211 {
212  int ret;
213  ret = fclose((FILE *)stream);
214  return ret;
215 }
216 
217 static int ZCALLBACK ferror_file_func (voidpf opaque, voidpf stream)
218 {
219  int ret;
220  ret = ferror((FILE *)stream);
221  return ret;
222 }
223 
224 void fill_fopen_filefunc (pzlib_filefunc_def)
225  zlib_filefunc_def* pzlib_filefunc_def;
226 {
227  pzlib_filefunc_def->zopen_file = fopen_file_func;
228  pzlib_filefunc_def->zread_file = fread_file_func;
229  pzlib_filefunc_def->zwrite_file = fwrite_file_func;
230  pzlib_filefunc_def->ztell_file = ftell_file_func;
231  pzlib_filefunc_def->zseek_file = fseek_file_func;
232  pzlib_filefunc_def->zclose_file = fclose_file_func;
233  pzlib_filefunc_def->zerror_file = ferror_file_func;
234  pzlib_filefunc_def->opaque = NULL;
235 }
236 
237 void fill_fopen64_filefunc (zlib_filefunc64_def* pzlib_filefunc_def)
238 {
239  pzlib_filefunc_def->zopen64_file = fopen64_file_func;
240  pzlib_filefunc_def->zread_file = fread_file_func;
241  pzlib_filefunc_def->zwrite_file = fwrite_file_func;
242  pzlib_filefunc_def->ztell64_file = ftell64_file_func;
243  pzlib_filefunc_def->zseek64_file = fseek64_file_func;
244  pzlib_filefunc_def->zclose_file = fclose_file_func;
245  pzlib_filefunc_def->zerror_file = ferror_file_func;
246  pzlib_filefunc_def->opaque = NULL;
247 }
open_file_func zopen32_file
Definition: ioapi.h:181
GLuint GLuint stream
testerror_file_func zerror_file
Definition: ioapi.h:170
testerror_file_func zerror_file
Definition: ioapi.h:154
#define NULL
Definition: ftobjs.h:61
ZPOS64_T call_ztell64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream)
Definition: ioapi.c:55
write_file_func zwrite_file
Definition: ioapi.h:150
#define OF(args)
Definition: zconf.h:146
#define ZLIB_FILEFUNC_MODE_READWRITEFILTER
Definition: ioapi.h:118
voidpf uLong int origin
Definition: ioapi.h:142
#define SEEK_END
Definition: zconf.h:251
#define ZCALLBACK
Definition: ioapi.h:128
#define ZLIB_FILEFUNC_MODE_READ
Definition: ioapi.h:116
const char * filename
Definition: ioapi.h:135
GLenum GLuint GLenum GLsizei const GLchar * buf
#define SEEK_CUR
Definition: zconf.h:250
write_file_func zwrite_file
Definition: ioapi.h:166
seek_file_func zseek32_file
Definition: ioapi.h:183
#define ZLIB_FILEFUNC_SEEK_CUR
Definition: ioapi.h:112
close_file_func zclose_file
Definition: ioapi.h:169
GLenum mode
read_file_func zread_file
Definition: ioapi.h:149
unsigned long uLong
Definition: zconf.h:222
seek_file_func zseek_file
Definition: ioapi.h:152
Byte FAR * voidpf
Definition: zconf.h:239
zlib_filefunc64_def zfile_func64
Definition: ioapi.h:180
#define ZLIB_FILEFUNC_MODE_CREATE
Definition: ioapi.h:121
unsigned long long int ZPOS64_T
Definition: ioapi.h:100
#define FTELLO_FUNC(stream)
Definition: ioapi.c:24
tell_file_func ztell_file
Definition: ioapi.h:151
void fill_fopen64_filefunc(zlib_filefunc64_def *pzlib_filefunc_def)
Definition: ioapi.c:237
GLintptr offset
#define ZLIB_FILEFUNC_MODE_EXISTING
Definition: ioapi.h:120
close_file_func zclose_file
Definition: ioapi.h:153
tell_file_func ztell32_file
Definition: ioapi.h:182
open_file_func zopen_file
Definition: ioapi.h:148
read_file_func zread_file
Definition: ioapi.h:165
#define FOPEN_FUNC(filename, mode)
Definition: ioapi.c:23
open64_file_func zopen64_file
Definition: ioapi.h:164
#define MAXU32
Definition: ioapi.h:95
#define ZLIB_FILEFUNC_SEEK_END
Definition: ioapi.h:113
#define FSEEKO_FUNC(stream, offset, origin)
Definition: ioapi.c:25
seek64_file_func zseek64_file
Definition: ioapi.h:168
void fill_fopen_filefunc(zlib_filefunc_def *pzlib_filefunc_def)
Definition: ioapi.c:224
#define ZLIB_FILEFUNC_SEEK_SET
Definition: ioapi.h:114
voidpf call_zopen64(const zlib_filefunc64_32_def *pfilefunc, const void *filename, int mode)
Definition: ioapi.c:31
GLsizeiptr size
long call_zseek64(const zlib_filefunc64_32_def *pfilefunc, voidpf filestream, ZPOS64_T offset, int origin)
Definition: ioapi.c:41
void fill_zlib_filefunc64_32_def_from_filefunc32(zlib_filefunc64_32_def *p_filefunc64_32, const zlib_filefunc_def *p_filefunc32)
Definition: ioapi.c:69
#define SEEK_SET
Definition: zconf.h:249
tell64_file_func ztell64_file
Definition: ioapi.h:167