[build] Skips RemoteExecuted bases tests on monodroid
[mono-project.git] / support / minizip / ioapi.c
blob813842b28f70f89c3e30053a1cfe3850e7b6e99a
1 /* ioapi.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API
4 Version 1.01e, February 12th, 2005
6 Copyright (C) 1998-2005 Gilles Vollant
7 */
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
13 #include "zlib.h"
14 #include "ioapi.h"
18 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
20 #ifndef SEEK_CUR
21 #define SEEK_CUR 1
22 #endif
24 #ifndef SEEK_END
25 #define SEEK_END 2
26 #endif
28 #ifndef SEEK_SET
29 #define SEEK_SET 0
30 #endif
32 static
33 voidpf ZCALLBACK fopen_file_func OF((
34 voidpf opaque,
35 const char* filename,
36 int mode));
38 static
39 uLong ZCALLBACK fread_file_func OF((
40 voidpf opaque,
41 voidpf stream,
42 void* buf,
43 uLong size));
45 static
46 uLong ZCALLBACK fwrite_file_func OF((
47 voidpf opaque,
48 voidpf stream,
49 const void* buf,
50 uLong size));
52 static
53 long ZCALLBACK ftell_file_func OF((
54 voidpf opaque,
55 voidpf stream));
57 static
58 long ZCALLBACK fseek_file_func OF((
59 voidpf opaque,
60 voidpf stream,
61 uLong offset,
62 int origin));
64 static
65 int ZCALLBACK fclose_file_func OF((
66 voidpf opaque,
67 voidpf stream));
69 static
70 int ZCALLBACK ferror_file_func OF((
71 voidpf opaque,
72 voidpf stream));
74 static
75 voidpf ZCALLBACK fopen_file_func (opaque, filename, mode)
76 voidpf opaque;
77 const char* filename;
78 int mode;
80 FILE* file = NULL;
81 const char* mode_fopen = NULL;
82 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
83 mode_fopen = "rb";
84 else
85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
86 mode_fopen = "r+b";
87 else
88 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
89 mode_fopen = "wb";
91 if ((filename!=NULL) && (mode_fopen != NULL))
92 file = fopen(filename, mode_fopen);
93 return file;
96 static
97 uLong ZCALLBACK fread_file_func (opaque, stream, buf, size)
98 voidpf opaque;
99 voidpf stream;
100 void* buf;
101 uLong size;
103 uLong ret;
104 ret = (uLong)fread(buf, 1, (size_t)size, (FILE *)stream);
105 return ret;
108 static
109 uLong ZCALLBACK fwrite_file_func (opaque, stream, buf, size)
110 voidpf opaque;
111 voidpf stream;
112 const void* buf;
113 uLong size;
115 uLong ret;
116 ret = (uLong)fwrite(buf, 1, (size_t)size, (FILE *)stream);
117 return ret;
120 static
121 long ZCALLBACK ftell_file_func (opaque, stream)
122 voidpf opaque;
123 voidpf stream;
125 long ret;
126 ret = ftell((FILE *)stream);
127 return ret;
130 static
131 long ZCALLBACK fseek_file_func (opaque, stream, offset, origin)
132 voidpf opaque;
133 voidpf stream;
134 uLong offset;
135 int origin;
137 int fseek_origin=0;
138 long ret;
139 switch (origin)
141 case ZLIB_FILEFUNC_SEEK_CUR :
142 fseek_origin = SEEK_CUR;
143 break;
144 case ZLIB_FILEFUNC_SEEK_END :
145 fseek_origin = SEEK_END;
146 break;
147 case ZLIB_FILEFUNC_SEEK_SET :
148 fseek_origin = SEEK_SET;
149 break;
150 default: return -1;
152 ret = 0;
153 fseek((FILE *)stream, offset, fseek_origin);
154 return ret;
157 static
158 int ZCALLBACK fclose_file_func (opaque, stream)
159 voidpf opaque;
160 voidpf stream;
162 int ret;
163 ret = fclose((FILE *)stream);
164 return ret;
167 static
168 int ZCALLBACK ferror_file_func (opaque, stream)
169 voidpf opaque;
170 voidpf stream;
172 int ret;
173 ret = ferror((FILE *)stream);
174 return ret;
177 void fill_fopen_filefunc (pzlib_filefunc_def)
178 zlib_filefunc_def* pzlib_filefunc_def;
180 pzlib_filefunc_def->zopen_file = fopen_file_func;
181 pzlib_filefunc_def->zread_file = fread_file_func;
182 pzlib_filefunc_def->zwrite_file = fwrite_file_func;
183 pzlib_filefunc_def->ztell_file = ftell_file_func;
184 pzlib_filefunc_def->zseek_file = fseek_file_func;
185 pzlib_filefunc_def->zclose_file = fclose_file_func;
186 pzlib_filefunc_def->zerror_file = ferror_file_func;
187 pzlib_filefunc_def->opaque = NULL;