Deleted Added
full compact
gzlib.c (230837) gzlib.c (237248)
1/* gzlib.c -- zlib functions common to reading and writing gzip files
1/* gzlib.c -- zlib functions common to reading and writing gzip files
2 * Copyright (C) 2004, 2010, 2011 Mark Adler
2 * Copyright (C) 2004, 2010, 2011, 2012 Mark Adler
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "gzguts.h"
7
8#if defined(_WIN32) && !defined(__BORLANDC__)
9# define LSEEK _lseeki64
10#else
11#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12# define LSEEK lseek64
13#else
14# define LSEEK lseek
15#endif
16#endif
17
18/* Local functions */
19local void gz_reset OF((gz_statep));
3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */
5
6#include "gzguts.h"
7
8#if defined(_WIN32) && !defined(__BORLANDC__)
9# define LSEEK _lseeki64
10#else
11#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0
12# define LSEEK lseek64
13#else
14# define LSEEK lseek
15#endif
16#endif
17
18/* Local functions */
19local void gz_reset OF((gz_statep));
20local gzFile gz_open OF((const char *, int, const char *));
20local gzFile gz_open OF((const void *, int, const char *));
21
22#if defined UNDER_CE
23
24/* Map the Windows error number in ERROR to a locale-dependent error message
25 string and return a pointer to it. Typically, the values for ERROR come
26 from GetLastError.
27
28 The string pointed to shall not be modified by the application, but may be

--- 55 unchanged lines hidden (view full) ---

84 state->seek = 0; /* no seek request pending */
85 gz_error(state, Z_OK, NULL); /* clear error */
86 state->x.pos = 0; /* no uncompressed data yet */
87 state->strm.avail_in = 0; /* no input data yet */
88}
89
90/* Open a gzip file either by name or file descriptor. */
91local gzFile gz_open(path, fd, mode)
21
22#if defined UNDER_CE
23
24/* Map the Windows error number in ERROR to a locale-dependent error message
25 string and return a pointer to it. Typically, the values for ERROR come
26 from GetLastError.
27
28 The string pointed to shall not be modified by the application, but may be

--- 55 unchanged lines hidden (view full) ---

84 state->seek = 0; /* no seek request pending */
85 gz_error(state, Z_OK, NULL); /* clear error */
86 state->x.pos = 0; /* no uncompressed data yet */
87 state->strm.avail_in = 0; /* no input data yet */
88}
89
90/* Open a gzip file either by name or file descriptor. */
91local gzFile gz_open(path, fd, mode)
92 const char *path;
92 const void *path;
93 int fd;
94 const char *mode;
95{
96 gz_statep state;
93 int fd;
94 const char *mode;
95{
96 gz_statep state;
97 size_t len;
98 int oflag;
99#ifdef O_CLOEXEC
100 int cloexec = 0;
101#endif
102#ifdef O_EXCL
103 int exclusive = 0;
104#endif
97
98 /* check input */
99 if (path == NULL)
100 return NULL;
101
102 /* allocate gzFile structure to return */
103 state = malloc(sizeof(gz_state));
104 if (state == NULL)

--- 23 unchanged lines hidden (view full) ---

128 state->mode = GZ_APPEND;
129 break;
130#endif
131 case '+': /* can't read and write at the same time */
132 free(state);
133 return NULL;
134 case 'b': /* ignore -- will request binary anyway */
135 break;
105
106 /* check input */
107 if (path == NULL)
108 return NULL;
109
110 /* allocate gzFile structure to return */
111 state = malloc(sizeof(gz_state));
112 if (state == NULL)

--- 23 unchanged lines hidden (view full) ---

136 state->mode = GZ_APPEND;
137 break;
138#endif
139 case '+': /* can't read and write at the same time */
140 free(state);
141 return NULL;
142 case 'b': /* ignore -- will request binary anyway */
143 break;
144#ifdef O_CLOEXEC
145 case 'e':
146 cloexec = 1;
147 break;
148#endif
149#ifdef O_EXCL
150 case 'x':
151 exclusive = 1;
152 break;
153#endif
136 case 'f':
137 state->strategy = Z_FILTERED;
138 break;
139 case 'h':
140 state->strategy = Z_HUFFMAN_ONLY;
141 break;
142 case 'R':
143 state->strategy = Z_RLE;

--- 19 unchanged lines hidden (view full) ---

163 if (state->direct) {
164 free(state);
165 return NULL;
166 }
167 state->direct = 1; /* for empty file */
168 }
169
170 /* save the path name for error messages */
154 case 'f':
155 state->strategy = Z_FILTERED;
156 break;
157 case 'h':
158 state->strategy = Z_HUFFMAN_ONLY;
159 break;
160 case 'R':
161 state->strategy = Z_RLE;

--- 19 unchanged lines hidden (view full) ---

181 if (state->direct) {
182 free(state);
183 return NULL;
184 }
185 state->direct = 1; /* for empty file */
186 }
187
188 /* save the path name for error messages */
171 state->path = malloc(strlen(path) + 1);
189#ifdef _WIN32
190 if (fd == -2) {
191 len = wcstombs(NULL, path, 0);
192 if (len == (size_t)-1)
193 len = 0;
194 }
195 else
196#endif
197 len = strlen(path);
198 state->path = malloc(len + 1);
172 if (state->path == NULL) {
173 free(state);
174 return NULL;
175 }
199 if (state->path == NULL) {
200 free(state);
201 return NULL;
202 }
176 strcpy(state->path, path);
203#ifdef _WIN32
204 if (fd == -2)
205 if (len)
206 wcstombs(state->path, path, len + 1);
207 else
208 *(state->path) = 0;
209 else
210#endif
211 strcpy(state->path, path);
177
212
178 /* open the file with the appropriate mode (or just use fd) */
179 state->fd = fd != -1 ? fd :
180 open(path,
213 /* compute the flags for open() */
214 oflag =
181#ifdef O_LARGEFILE
215#ifdef O_LARGEFILE
182 O_LARGEFILE |
216 O_LARGEFILE |
183#endif
184#ifdef O_BINARY
217#endif
218#ifdef O_BINARY
185 O_BINARY |
219 O_BINARY |
186#endif
220#endif
187 (state->mode == GZ_READ ?
188 O_RDONLY :
189 (O_WRONLY | O_CREAT | (
190 state->mode == GZ_WRITE ?
191 O_TRUNC :
192 O_APPEND))),
193 0666);
221#ifdef O_CLOEXEC
222 (cloexec ? O_CLOEXEC : 0) |
223#endif
224 (state->mode == GZ_READ ?
225 O_RDONLY :
226 (O_WRONLY | O_CREAT |
227#ifdef O_EXCL
228 (exclusive ? O_EXCL : 0) |
229#endif
230 (state->mode == GZ_WRITE ?
231 O_TRUNC :
232 O_APPEND)));
233
234 /* open the file with the appropriate flags (or just use fd) */
235 state->fd = fd > -1 ? fd : (
236#ifdef _WIN32
237 fd == -2 ? _wopen(path, oflag, 0666) :
238#endif
239 open(path, oflag, 0666));
194 if (state->fd == -1) {
195 free(state->path);
196 free(state);
197 return NULL;
198 }
199 if (state->mode == GZ_APPEND)
200 state->mode = GZ_WRITE; /* simplify later checks */
201

--- 38 unchanged lines hidden (view full) ---

240 return NULL;
241 sprintf(path, "<fd:%d>", fd); /* for debugging */
242 gz = gz_open(path, fd, mode);
243 free(path);
244 return gz;
245}
246
247/* -- see zlib.h -- */
240 if (state->fd == -1) {
241 free(state->path);
242 free(state);
243 return NULL;
244 }
245 if (state->mode == GZ_APPEND)
246 state->mode = GZ_WRITE; /* simplify later checks */
247

--- 38 unchanged lines hidden (view full) ---

286 return NULL;
287 sprintf(path, "<fd:%d>", fd); /* for debugging */
288 gz = gz_open(path, fd, mode);
289 free(path);
290 return gz;
291}
292
293/* -- see zlib.h -- */
294#ifdef _WIN32
295gzFile ZEXPORT gzopen_w(path, mode)
296 const wchar_t *path;
297 const char *mode;
298{
299 return gz_open(path, -2, mode);
300}
301#endif
302
303/* -- see zlib.h -- */
248int ZEXPORT gzbuffer(file, size)
249 gzFile file;
250 unsigned size;
251{
252 gz_statep state;
253
254 /* get internal structure and check integrity */
255 if (file == NULL)

--- 309 unchanged lines hidden ---
304int ZEXPORT gzbuffer(file, size)
305 gzFile file;
306 unsigned size;
307{
308 gz_statep state;
309
310 /* get internal structure and check integrity */
311 if (file == NULL)

--- 309 unchanged lines hidden ---