summaryrefslogtreecommitdiff
path: root/contrib/minizip/iowin32.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
committerMark Adler <madler@alumni.caltech.edu>2011-09-09 23:22:10 -0700
commit8e34b3a8024c028dd9fd21d70525fc6d215efde5 (patch)
tree896a32f54abdf42ae3c1bb3c5d5627668b481ce4 /contrib/minizip/iowin32.c
parent13a294f044ef0a89b2dcbfbb5d4d4c792673348e (diff)
downloadzlib-1.2.0.2.tar.gz
zlib-1.2.0.2.tar.bz2
zlib-1.2.0.2.zip
zlib 1.2.0.2v1.2.0.2
Diffstat (limited to 'contrib/minizip/iowin32.c')
-rw-r--r--contrib/minizip/iowin32.c542
1 files changed, 271 insertions, 271 deletions
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c
index f1f5546..53198b6 100644
--- a/contrib/minizip/iowin32.c
+++ b/contrib/minizip/iowin32.c
@@ -1,271 +1,271 @@
1/* iowin32.c -- IO base function header for compress/uncompress .zip 1/* iowin32.c -- IO base function header for compress/uncompress .zip
2 files using zlib + zip or unzip API 2 files using zlib + zip or unzip API
3 This IO API version uses the Win32 API (for Microsoft Windows) 3 This IO API version uses the Win32 API (for Microsoft Windows)
4 4
5 Version 0.21, March 10th, 2003 5 Version 0.22, May 19th, 2003
6 6
7 Copyright (C) 1998-2003 Gilles Vollant 7 Copyright (C) 1998-2003 Gilles Vollant
8*/ 8*/
9 9
10#include <windows.h> 10#include <windows.h>
11#include <stdlib.h> 11#include <stdlib.h>
12 12
13#include "zlib.h" 13#include "zlib.h"
14#include "ioapi.h" 14#include "ioapi.h"
15#include "iowin32.h" 15#include "iowin32.h"
16 16
17#ifndef INVALID_HANDLE_VALUE 17#ifndef INVALID_HANDLE_VALUE
18#define INVALID_HANDLE_VALUE (0xFFFFFFFF) 18#define INVALID_HANDLE_VALUE (0xFFFFFFFF)
19#endif 19#endif
20 20
21#ifndef INVALID_SET_FILE_POINTER 21#ifndef INVALID_SET_FILE_POINTER
22#define INVALID_SET_FILE_POINTER ((DWORD)-1) 22#define INVALID_SET_FILE_POINTER ((DWORD)-1)
23#endif 23#endif
24 24
25voidpf ZCALLBACK win32_open_file_func OF(( 25voidpf ZCALLBACK win32_open_file_func OF((
26 voidpf opaque, 26 voidpf opaque,
27 const char* filename, 27 const char* filename,
28 int mode)); 28 int mode));
29 29
30uLong ZCALLBACK win32_read_file_func OF(( 30uLong ZCALLBACK win32_read_file_func OF((
31 voidpf opaque, 31 voidpf opaque,
32 voidpf stream, 32 voidpf stream,
33 void* buf, 33 void* buf,
34 uLong size)); 34 uLong size));
35 35
36uLong ZCALLBACK win32_write_file_func OF(( 36uLong ZCALLBACK win32_write_file_func OF((
37 voidpf opaque, 37 voidpf opaque,
38 voidpf stream, 38 voidpf stream,
39 const void* buf, 39 const void* buf,
40 uLong size)); 40 uLong size));
41 41
42long ZCALLBACK win32_tell_file_func OF(( 42long ZCALLBACK win32_tell_file_func OF((
43 voidpf opaque, 43 voidpf opaque,
44 voidpf stream)); 44 voidpf stream));
45 45
46long ZCALLBACK win32_seek_file_func OF(( 46long ZCALLBACK win32_seek_file_func OF((
47 voidpf opaque, 47 voidpf opaque,
48 voidpf stream, 48 voidpf stream,
49 uLong offset, 49 uLong offset,
50 int origin)); 50 int origin));
51 51
52long ZCALLBACK win32_close_file_func OF(( 52long ZCALLBACK win32_close_file_func OF((
53 voidpf opaque, 53 voidpf opaque,
54 voidpf stream)); 54 voidpf stream));
55 55
56int ZCALLBACK win32_error_file_func OF(( 56int ZCALLBACK win32_error_file_func OF((
57 voidpf opaque, 57 voidpf opaque,
58 voidpf stream)); 58 voidpf stream));
59 59
60typedef struct 60typedef struct
61{ 61{
62 HANDLE hf; 62 HANDLE hf;
63 int error; 63 int error;
64} WIN32FILE_IOWIN; 64} WIN32FILE_IOWIN;
65 65
66voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode) 66voidpf ZCALLBACK win32_open_file_func (opaque, filename, mode)
67 voidpf opaque; 67 voidpf opaque;
68 const char* filename; 68 const char* filename;
69 int mode; 69 int mode;
70{ 70{
71 const char* mode_fopen = NULL; 71 const char* mode_fopen = NULL;
72 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ; 72 DWORD dwDesiredAccess,dwCreationDisposition,dwShareMode,dwFlagsAndAttributes ;
73 HANDLE hFile = 0; 73 HANDLE hFile = 0;
74 voidpf ret=NULL; 74 voidpf ret=NULL;
75 75
76 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0; 76 dwDesiredAccess = dwShareMode = dwFlagsAndAttributes = 0;
77 77
78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ) 78 if ((mode & ZLIB_FILEFUNC_MODE_READWRITEFILTER)==ZLIB_FILEFUNC_MODE_READ)
79 { 79 {
80 dwDesiredAccess = GENERIC_READ; 80 dwDesiredAccess = GENERIC_READ;
81 dwCreationDisposition = OPEN_EXISTING; 81 dwCreationDisposition = OPEN_EXISTING;
82 dwShareMode = FILE_SHARE_READ; 82 dwShareMode = FILE_SHARE_READ;
83 } 83 }
84 else 84 else
85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING) 85 if (mode & ZLIB_FILEFUNC_MODE_EXISTING)
86 { 86 {
87 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 87 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
88 dwCreationDisposition = OPEN_EXISTING; 88 dwCreationDisposition = OPEN_EXISTING;
89 } 89 }
90 else 90 else
91 if (mode & ZLIB_FILEFUNC_MODE_CREATE) 91 if (mode & ZLIB_FILEFUNC_MODE_CREATE)
92 { 92 {
93 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ; 93 dwDesiredAccess = GENERIC_WRITE | GENERIC_READ;
94 dwCreationDisposition = CREATE_ALWAYS; 94 dwCreationDisposition = CREATE_ALWAYS;
95 } 95 }
96 96
97 if ((filename!=NULL) && (dwDesiredAccess != 0)) 97 if ((filename!=NULL) && (dwDesiredAccess != 0))
98 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL, 98 hFile = CreateFile((LPCTSTR)filename, dwDesiredAccess, dwShareMode, NULL,
99 dwCreationDisposition, dwFlagsAndAttributes, NULL); 99 dwCreationDisposition, dwFlagsAndAttributes, NULL);
100 100
101 if (hFile == INVALID_HANDLE_VALUE) 101 if (hFile == INVALID_HANDLE_VALUE)
102 hFile = NULL; 102 hFile = NULL;
103 103
104 if (hFile != NULL) 104 if (hFile != NULL)
105 { 105 {
106 WIN32FILE_IOWIN w32fiow; 106 WIN32FILE_IOWIN w32fiow;
107 w32fiow.hf = hFile; 107 w32fiow.hf = hFile;
108 w32fiow.error = 0; 108 w32fiow.error = 0;
109 ret = malloc(sizeof(WIN32FILE_IOWIN)); 109 ret = malloc(sizeof(WIN32FILE_IOWIN));
110 if (ret==NULL) 110 if (ret==NULL)
111 CloseHandle(hFile); 111 CloseHandle(hFile);
112 else *((WIN32FILE_IOWIN*)ret) = w32fiow; 112 else *((WIN32FILE_IOWIN*)ret) = w32fiow;
113 } 113 }
114 return ret; 114 return ret;
115} 115}
116 116
117 117
118uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size) 118uLong ZCALLBACK win32_read_file_func (opaque, stream, buf, size)
119 voidpf opaque; 119 voidpf opaque;
120 voidpf stream; 120 voidpf stream;
121 void* buf; 121 void* buf;
122 uLong size; 122 uLong size;
123{ 123{
124 uLong ret=0; 124 uLong ret=0;
125 HANDLE hFile = NULL; 125 HANDLE hFile = NULL;
126 if (stream!=NULL) 126 if (stream!=NULL)
127 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 127 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
128 if (hFile != NULL) 128 if (hFile != NULL)
129 if (!ReadFile(hFile, buf, size, &ret, NULL)) 129 if (!ReadFile(hFile, buf, size, &ret, NULL))
130 { 130 {
131 DWORD dwErr = GetLastError(); 131 DWORD dwErr = GetLastError();
132 if (dwErr == ERROR_HANDLE_EOF) 132 if (dwErr == ERROR_HANDLE_EOF)
133 dwErr = 0; 133 dwErr = 0;
134 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 134 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
135 } 135 }
136 136
137 return ret; 137 return ret;
138} 138}
139 139
140 140
141uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size) 141uLong ZCALLBACK win32_write_file_func (opaque, stream, buf, size)
142 voidpf opaque; 142 voidpf opaque;
143 voidpf stream; 143 voidpf stream;
144 const void* buf; 144 const void* buf;
145 uLong size; 145 uLong size;
146{ 146{
147 uLong ret=0; 147 uLong ret=0;
148 HANDLE hFile = NULL; 148 HANDLE hFile = NULL;
149 if (stream!=NULL) 149 if (stream!=NULL)
150 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 150 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
151 151
152 if (hFile !=NULL) 152 if (hFile !=NULL)
153 if (!WriteFile(hFile, buf, size, &ret, NULL)) 153 if (!WriteFile(hFile, buf, size, &ret, NULL))
154 { 154 {
155 DWORD dwErr = GetLastError(); 155 DWORD dwErr = GetLastError();
156 if (dwErr == ERROR_HANDLE_EOF) 156 if (dwErr == ERROR_HANDLE_EOF)
157 dwErr = 0; 157 dwErr = 0;
158 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 158 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
159 } 159 }
160 160
161 return ret; 161 return ret;
162} 162}
163 163
164long ZCALLBACK win32_tell_file_func (opaque, stream) 164long ZCALLBACK win32_tell_file_func (opaque, stream)
165 voidpf opaque; 165 voidpf opaque;
166 voidpf stream; 166 voidpf stream;
167{ 167{
168 long ret=-1; 168 long ret=-1;
169 HANDLE hFile = NULL; 169 HANDLE hFile = NULL;
170 if (stream!=NULL) 170 if (stream!=NULL)
171 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 171 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
172 if (hFile != NULL) 172 if (hFile != NULL)
173 { 173 {
174 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT); 174 DWORD dwSet = SetFilePointer(hFile, 0, NULL, FILE_CURRENT);
175 if (dwSet == INVALID_SET_FILE_POINTER) 175 if (dwSet == INVALID_SET_FILE_POINTER)
176 { 176 {
177 DWORD dwErr = GetLastError(); 177 DWORD dwErr = GetLastError();
178 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 178 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
179 ret = -1; 179 ret = -1;
180 } 180 }
181 else 181 else
182 ret=(long)dwSet; 182 ret=(long)dwSet;
183 } 183 }
184 return ret; 184 return ret;
185} 185}
186 186
187long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin) 187long ZCALLBACK win32_seek_file_func (opaque, stream, offset, origin)
188 voidpf opaque; 188 voidpf opaque;
189 voidpf stream; 189 voidpf stream;
190 uLong offset; 190 uLong offset;
191 int origin; 191 int origin;
192{ 192{
193 DWORD dwMoveMethod=0xFFFFFFFF; 193 DWORD dwMoveMethod=0xFFFFFFFF;
194 HANDLE hFile = NULL; 194 HANDLE hFile = NULL;
195 195
196 long ret=-1; 196 long ret=-1;
197 if (stream!=NULL) 197 if (stream!=NULL)
198 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 198 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
199 switch (origin) 199 switch (origin)
200 { 200 {
201 case ZLIB_FILEFUNC_SEEK_CUR : 201 case ZLIB_FILEFUNC_SEEK_CUR :
202 dwMoveMethod = FILE_CURRENT; 202 dwMoveMethod = FILE_CURRENT;
203 break; 203 break;
204 case ZLIB_FILEFUNC_SEEK_END : 204 case ZLIB_FILEFUNC_SEEK_END :
205 dwMoveMethod = FILE_END; 205 dwMoveMethod = FILE_END;
206 break; 206 break;
207 case ZLIB_FILEFUNC_SEEK_SET : 207 case ZLIB_FILEFUNC_SEEK_SET :
208 dwMoveMethod = FILE_BEGIN; 208 dwMoveMethod = FILE_BEGIN;
209 break; 209 break;
210 default: return -1; 210 default: return -1;
211 } 211 }
212 212
213 if (hFile != NULL) 213 if (hFile != NULL)
214 { 214 {
215 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod); 215 DWORD dwSet = SetFilePointer(hFile, offset, NULL, dwMoveMethod);
216 if (dwSet == INVALID_SET_FILE_POINTER) 216 if (dwSet == INVALID_SET_FILE_POINTER)
217 { 217 {
218 DWORD dwErr = GetLastError(); 218 DWORD dwErr = GetLastError();
219 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr; 219 ((WIN32FILE_IOWIN*)stream) -> error=(int)dwErr;
220 ret = -1; 220 ret = -1;
221 } 221 }
222 else 222 else
223 ret=0; 223 ret=0;
224 } 224 }
225 return ret; 225 return ret;
226} 226}
227 227
228long ZCALLBACK win32_close_file_func (opaque, stream) 228long ZCALLBACK win32_close_file_func (opaque, stream)
229 voidpf opaque; 229 voidpf opaque;
230 voidpf stream; 230 voidpf stream;
231{ 231{
232 long ret=-1; 232 long ret=-1;
233 233
234 if (stream!=NULL) 234 if (stream!=NULL)
235 { 235 {
236 HANDLE hFile; 236 HANDLE hFile;
237 hFile = ((WIN32FILE_IOWIN*)stream) -> hf; 237 hFile = ((WIN32FILE_IOWIN*)stream) -> hf;
238 if (hFile != NULL) 238 if (hFile != NULL)
239 { 239 {
240 CloseHandle(hFile); 240 CloseHandle(hFile);
241 ret=0; 241 ret=0;
242 } 242 }
243 free(stream); 243 free(stream);
244 } 244 }
245 return ret; 245 return ret;
246} 246}
247 247
248int ZCALLBACK win32_error_file_func (opaque, stream) 248int ZCALLBACK win32_error_file_func (opaque, stream)
249 voidpf opaque; 249 voidpf opaque;
250 voidpf stream; 250 voidpf stream;
251{ 251{
252 int ret=-1; 252 int ret=-1;
253 if (stream!=NULL) 253 if (stream!=NULL)
254 { 254 {
255 ret = ((WIN32FILE_IOWIN*)stream) -> error; 255 ret = ((WIN32FILE_IOWIN*)stream) -> error;
256 } 256 }
257 return ret; 257 return ret;
258} 258}
259 259
260void fill_win32_filefunc (pzlib_filefunc_def) 260void fill_win32_filefunc (pzlib_filefunc_def)
261 zlib_filefunc_def* pzlib_filefunc_def; 261 zlib_filefunc_def* pzlib_filefunc_def;
262{ 262{
263 pzlib_filefunc_def->zopen_file = win32_open_file_func; 263 pzlib_filefunc_def->zopen_file = win32_open_file_func;
264 pzlib_filefunc_def->zread_file = win32_read_file_func; 264 pzlib_filefunc_def->zread_file = win32_read_file_func;
265 pzlib_filefunc_def->zwrite_file = win32_write_file_func; 265 pzlib_filefunc_def->zwrite_file = win32_write_file_func;
266 pzlib_filefunc_def->ztell_file = win32_tell_file_func; 266 pzlib_filefunc_def->ztell_file = win32_tell_file_func;
267 pzlib_filefunc_def->zseek_file = win32_seek_file_func; 267 pzlib_filefunc_def->zseek_file = win32_seek_file_func;
268 pzlib_filefunc_def->zclose_file = win32_close_file_func; 268 pzlib_filefunc_def->zclose_file = win32_close_file_func;
269 pzlib_filefunc_def->zerror_file = win32_error_file_func; 269 pzlib_filefunc_def->zerror_file = win32_error_file_func;
270 pzlib_filefunc_def->opaque=NULL; 270 pzlib_filefunc_def->opaque=NULL;
271} 271}