15 # define NO_GZCOMPRESS 24 # define Z_BUFSIZE 4096 26 # define Z_BUFSIZE 16384 29 #ifndef Z_PRINTF_BUFSIZE 30 # define Z_PRINTF_BUFSIZE 4096 34 # pragma map (fdopen , "\174\174FDOPEN") 35 FILE *fdopen(
int,
const char *);
43 #define ALLOC(size) malloc(size) 44 #define TRYFREE(p) {if (p) free(p);} 49 #define ASCII_FLAG 0x01 51 #define EXTRA_FIELD 0x04 52 #define ORIG_NAME 0x08 101 char *p = (
char*)mode;
106 if (!path || !mode)
return Z_NULL;
128 if (s->
path == NULL) {
131 strcpy(s->
path, path);
135 if (*p ==
'r') s->
mode =
'r';
136 if (*p ==
'w' || *p ==
'a') s->
mode =
'w';
137 if (*p >=
'0' && *p <=
'9') {
139 }
else if (*p ==
'f') {
141 }
else if (*p ==
'h') {
143 }
else if (*p ==
'R') {
148 }
while (*p++ && m != fmode +
sizeof(fmode));
151 if (s->
mode ==
'w') {
181 s->
file = fd < 0 ?
F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode);
183 if (s->
file == NULL) {
186 if (s->
mode ==
'w') {
189 fprintf(s->
file,
"%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1],
212 return gz_open (path, mode, -1);
228 return gz_open (name, mode, fd);
264 if (s->z_eof)
return EOF;
265 if (s->stream.avail_in == 0) {
268 if (s->stream.avail_in == 0) {
270 if (ferror(s->file)) s->z_err =
Z_ERRNO;
273 s->stream.next_in = s->inbuf;
275 s->stream.avail_in--;
276 return *(s->stream.next_in)++;
299 len = s->stream.avail_in;
301 if (len) s->inbuf[0] = s->stream.next_in[0];
303 len = (
uInt)fread(s->inbuf + len, 1,
Z_BUFSIZE >> len, s->file);
304 if (len == 0 && ferror(s->file)) s->z_err =
Z_ERRNO;
305 s->stream.avail_in += len;
306 s->stream.next_in = s->inbuf;
307 if (s->stream.avail_in < 2) {
308 s->transparent = s->stream.avail_in;
314 if (s->stream.next_in[0] != gz_magic[0] ||
315 s->stream.next_in[1] != gz_magic[1]) {
319 s->stream.avail_in -= 2;
320 s->stream.next_in += 2;
331 for (len = 0; len < 6; len++) (
void)
get_byte(s);
337 while (len-- != 0 &&
get_byte(s) != EOF) ;
340 while ((c =
get_byte(s)) != 0 && c != EOF) ;
343 while ((c =
get_byte(s)) != 0 && c != EOF) ;
346 for (len = 0; len < 2; len++) (
void)
get_byte(s);
364 if (s->stream.state != NULL) {
365 if (s->mode ==
'w') {
371 }
else if (s->mode ==
'r') {
375 if (s->file != NULL && fclose(s->file)) {
381 if (s->z_err < 0) err = s->z_err;
408 next_out = (
Byte*)buf;
413 *next_out++ = s->
back;
446 if (len == 0) s->
z_eof = 1;
455 if (ferror(s->
file)) {
508 return gzread(file, &c, 1) == 1 ? c : -1;
521 if (s == NULL || s->
mode !=
'r' || c == EOF || s->
back != EOF)
return EOF;
548 while (--len > 0 &&
gzread(file, buf, 1) == 1 && *buf++ !=
'\n') ;
550 return b == buf && len > 0 ?
Z_NULL :
b;
554 #ifndef NO_GZCOMPRESS 609 buf[
sizeof(
buf) - 1] = 0;
610 va_start(va, format);
612 # ifdef HAS_vsprintf_void 613 (
void)vsprintf(buf, format, va);
615 for (len = 0; len <
sizeof(
buf); len++)
616 if (buf[len] == 0)
break;
618 len = vsprintf(buf, format, va);
622 # ifdef HAS_vsnprintf_void 623 (
void)vsnprintf(buf,
sizeof(buf), format, va);
627 len = vsnprintf(buf,
sizeof(buf), format, va);
631 if (len <= 0 || len >= (
int)
sizeof(buf) || buf[
sizeof(buf) - 1] != 0)
633 return gzwrite(file, buf, (
unsigned)len);
637 int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
638 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20)
641 int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10,
642 a11, a12, a13, a14, a15, a16, a17, a18, a19, a20;
647 buf[
sizeof(
buf) - 1] = 0;
649 # ifdef HAS_sprintf_void 650 sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
651 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
652 for (len = 0; len <
sizeof(
buf); len++)
653 if (buf[len] == 0)
break;
655 len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8,
656 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
659 # ifdef HAS_snprintf_void 660 snprintf(buf,
sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
661 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
664 len = snprintf(buf,
sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8,
665 a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20);
668 if (len <= 0 || len >=
sizeof(buf) || buf[
sizeof(buf) - 1] != 0)
670 return gzwrite(file, buf, len);
682 unsigned char cc = (
unsigned char) c;
684 return gzwrite(file, &cc, 1) == 1 ? (
int)cc : -1;
697 return gzwrite(file, (
char*)s, (
unsigned)strlen(s));
774 if (s == NULL || whence ==
SEEK_END ||
779 if (s->
mode ==
'w') {
786 if (offset < 0)
return -1L;
799 if (size == 0)
return -1L;
812 if (offset < 0)
return -1L;
821 s->
in = s->
out = offset;
826 if (offset >= s->
out) {
837 if (offset && s->
back != EOF) {
848 if (size <= 0)
return -1L;
862 if (s == NULL || s->
mode !=
'r')
return -1;
900 if (s == NULL || s->
mode !=
'r')
return 0;
901 if (s->
z_eof)
return 1;
913 if (s == NULL || s->
mode !=
'r')
return 0;
925 for (n = 0; n < 4; n++) {
926 fputc((
int)(x & 0xff), file);
960 if (s->
mode ==
'w') {
975 # define zstrerror(errnum) strerror(errnum) 977 # define zstrerror(errnum) "" 999 if (*errnum ==
Z_OK)
return (
const char*)
"";
1003 if (m == NULL || *m ==
'\0') m = (
char*)
ERR_MSG(s->
z_err);
1006 s->
msg = (
char*)
ALLOC(strlen(s->
path) + strlen(m) + 3);
1009 strcat(s->
msg,
": ");
1011 return (
const char*)s->
msg;
1022 if (s == NULL)
return;
int ZEXPORT gzgetc(gzFile file)
int ZEXPORT deflateParams(z_streamp strm, int level, int strategy)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
int ZEXPORT inflateReset(z_streamp strm)
void zmemcpy(Bytef *dest, const Bytef *source, uInt len)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
voidp malloc OF((uInt size))
png_infop png_charpp name
local uLong getLong(gz_stream *s)
struct gz_stream gz_stream
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
int ZEXPORT gzsetparams(gzFile file, int level, int strategy)
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
int ZEXPORT deflateEnd(z_streamp strm)
int ZEXPORT gzungetc(int c, gzFile file)
static int const gz_magic[2]
local gzFile gz_open(char *path, const char *mode, int fd) const
int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
#define inflateInit2(strm, windowBits)
#define zstrerror(errnum)
int ZEXPORT gzflush(gzFile file, int flush)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, unsigned len)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
local void check_header(gz_stream *s)
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
local int get_byte(gz_stream *s)
int ZEXPORTVA gzprintf(gzFile file, const char *format, int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9, int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18, int a19, int a20)
int ZEXPORT gzputs(gzFile file, const char *s)
local int destroy(gz_stream *s)
int ZEXPORT gzrewind(gzFile file)
int ZEXPORT deflate(z_streamp strm, int flush)
int ZEXPORT gzeof(gzFile file)
int ZEXPORT gzdirect(gzFile file)
z_off_t ZEXPORT gztell(gzFile file)
std::string sprintf(char const *__restrict fmt,...)
void ZEXPORT gzclearerr(gzFile file)
#define F_OPEN(name, mode)
local void putLong(FILE *file, uLong x)
int ZEXPORT inflate(z_streamp strm, int flush)
#define Z_DEFAULT_STRATEGY
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
local int do_flush(gzFile file, int flush)
void zmemzero(Bytef *dest, uInt len)
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT gzputc(gzFile file, int c)
#define Z_DEFAULT_COMPRESSION