15 # define NO_GZCOMPRESS
19 struct internal_state {
int dummy;};
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;
111 s->stream.zalloc = (alloc_func)0;
112 s->stream.zfree = (free_func)0;
113 s->stream.opaque = (
voidpf)0;
114 s->stream.next_in = s->inbuf =
Z_NULL;
115 s->stream.next_out = s->outbuf =
Z_NULL;
116 s->stream.avail_in = s->stream.avail_out = 0;
127 s->path = (
char*)
ALLOC(strlen(path)+1);
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],
199 s->start = ftell(s->file) - s->stream.avail_in;
212 return gz_open (path, mode, -1);
226 sprintf(name,
"<fd:%d>", fd);
228 return gz_open (name, mode, fd);
244 if (s->stream.avail_out == 0) {
246 s->stream.next_out = s->outbuf;
264 if (s->z_eof)
return EOF;
265 if (s->stream.avail_in == 0) {
267 s->stream.avail_in = (
uInt)fread(s->inbuf, 1,
Z_BUFSIZE, s->file);
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);
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;
409 s->stream.next_out = (
Bytef*)buf;
410 s->stream.avail_out =
len;
412 if (s->stream.avail_out && s->back !=
EOF) {
413 *next_out++ = s->back;
414 s->stream.next_out++;
415 s->stream.avail_out--;
425 while (s->stream.avail_out != 0) {
427 if (s->transparent) {
429 uInt n = s->stream.avail_in;
430 if (n > s->stream.avail_out) n = s->stream.avail_out;
432 zmemcpy(s->stream.next_out, s->stream.next_in, n);
434 s->stream.next_out = next_out;
435 s->stream.next_in +=
n;
436 s->stream.avail_out -=
n;
437 s->stream.avail_in -=
n;
439 if (s->stream.avail_out > 0) {
440 s->stream.avail_out -=
441 (
uInt)fread(next_out, 1, s->stream.avail_out, s->file);
443 len -= s->stream.avail_out;
446 if (len == 0) s->z_eof = 1;
449 if (s->stream.avail_in == 0 && !s->z_eof) {
452 s->stream.avail_in = (
uInt)fread(s->inbuf, 1,
Z_BUFSIZE, s->file);
453 if (s->stream.avail_in == 0) {
455 if (ferror(s->file)) {
460 s->stream.next_in = s->inbuf;
462 s->in += s->stream.avail_in;
463 s->out += s->stream.avail_out;
465 s->in -= s->stream.avail_in;
466 s->out -= s->stream.avail_out;
470 s->crc =
crc32(s->crc, start, (
uInt)(s->stream.next_out - start));
471 start = s->stream.next_out;
482 if (s->z_err ==
Z_OK) {
488 if (s->z_err !=
Z_OK || s->z_eof)
break;
490 s->crc =
crc32(s->crc, start, (
uInt)(s->stream.next_out - start));
492 if (len == s->stream.avail_out &&
495 return (
int)(len - s->stream.avail_out);
508 return gzread(file, &c, 1) == 1 ? c : -1;
521 if (s ==
NULL || s->mode !=
'r' || c ==
EOF || s->back !=
EOF)
return EOF;
525 if (s->last) s->z_err =
Z_OK;
548 while (--len > 0 &&
gzread(file, buf, 1) == 1 && *buf++ !=
'\n') ;
550 return b == buf && len > 0 ?
Z_NULL :
b;
554 #ifndef NO_GZCOMPRESS
568 s->stream.next_in = (
Bytef*)buf;
569 s->stream.avail_in =
len;
571 while (s->stream.avail_in != 0) {
573 if (s->stream.avail_out == 0) {
575 s->stream.next_out = s->outbuf;
582 s->in += s->stream.avail_in;
583 s->out += s->stream.avail_out;
585 s->in -= s->stream.avail_in;
586 s->out -= s->stream.avail_out;
587 if (s->z_err !=
Z_OK)
break;
589 s->crc =
crc32(s->crc, (
const Bytef *)buf, len);
591 return (
int)(len - s->stream.avail_in);
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);
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);
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));
715 s->stream.avail_in = 0;
721 if ((
uInt)fwrite(s->outbuf, 1, len, s->file) !=
len) {
725 s->stream.next_out = s->outbuf;
729 s->out += s->stream.avail_out;
730 s->z_err =
deflate(&(s->stream), flush);
731 s->out -= s->stream.avail_out;
739 done = (s->stream.avail_out != 0 || s->z_err ==
Z_STREAM_END);
779 if (s->mode ==
'w') {
786 if (offset < 0)
return -1L;
791 if (s->inbuf ==
Z_NULL)
return -1L;
798 size =
gzwrite(file, s->inbuf, size);
799 if (size == 0)
return -1L;
812 if (offset < 0)
return -1L;
814 if (s->transparent) {
817 s->stream.avail_in = 0;
818 s->stream.next_in = s->inbuf;
819 if (fseek(s->file, offset,
SEEK_SET) < 0)
return -1L;
826 if (offset >= s->out) {
833 if (offset != 0 && s->outbuf ==
Z_NULL) {
835 if (s->outbuf ==
Z_NULL)
return -1L;
837 if (offset && s->back !=
EOF) {
848 if (size <= 0)
return -1L;
862 if (s ==
NULL || s->mode !=
'r')
return -1;
867 s->stream.avail_in = 0;
868 s->stream.next_in = s->inbuf;
873 return fseek(s->file, s->start,
SEEK_SET);
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;
914 return s->transparent;
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);
1008 strcpy(s->msg, s->path);
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)
char *ZEXPORT gzgets(gzFile file, char *buf, int len)
void zmemzero(Bytef *dest, uInt len)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
int ZEXPORT inflateEnd(z_streamp strm)
void zmemcpy(Bytef *dest, const Bytef *source, uInt len)
gzFile ZEXPORT gzdopen(int fd, const char *mode)
local uLong getLong(gz_stream *s)
int ZEXPORT gzclose(gzFile file)
struct gz_stream gz_stream
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
EGLImageKHR EGLint * name
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]
#define Z_DEFAULT_COMPRESSION
local gzFile gz_open(char *path, const char *mode, int fd) const
GLsizei const GLchar *const * path
gzFile ZEXPORT gzopen(char *path, const char *mode) const
#define zstrerror(errnum)
int ZEXPORT gzflush(gzFile file, int flush)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
local void check_header(gz_stream *s)
#define F_OPEN(name, mode)
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)
#define inflateInit2(strm, windowBits)
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
GLint GLenum GLsizei GLsizei GLsizei GLint GLenum format
#define Z_DEFAULT_STRATEGY
int ZEXPORT inflate(z_streamp strm, int flush)
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 inflateReset(z_streamp strm)
int ZEXPORT gzeof(gzFile file)
int ZEXPORT gzdirect(gzFile file)
z_off_t ZEXPORT gztell(gzFile file)
void ZEXPORT gzclearerr(gzFile file)
GLenum GLuint GLsizei const GLchar * buf
GLenum GLsizei GLsizei GLsizei GLsizei GLbitfield flags
local void putLong(FILE *file, uLong x)
GLdouble GLdouble GLdouble b
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
z_off_t ZEXPORT gzseek(gzFile file, z_off_t offset, int whence)
local int do_flush(gzFile file, int flush)
int ZEXPORT gzputc(gzFile file, int c)