author  Ryan C. Gordon <icculus@icculus.org> 
Fri, 19 Dec 2003 01:49:12 +0000  
changeset 612  03b07cbd1bc7 
parent 602  691c1eadb8b7 
permissions  rwrr 
602
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1 
/* gzio.c  IO on .gz files 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

2 
* Copyright (C) 19952003 Jeanloup Gailly. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

3 
* For conditions of distribution and use, see copyright notice in zlib.h 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

4 
* 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

5 
* Compile this file with DNO_GZCOMPRESS to avoid the compression code. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

6 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

7 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

8 
/* @(#) $Id: gzio.c,v 1.1 2003/12/07 05:29:20 icculus Exp $ */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

9 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

10 
#include <stdio.h> 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

11 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

12 
#include "zutil.h" 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

13 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

14 
#ifdef NO_DEFLATE /* for compatiblity with old definition */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

15 
# define NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

16 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

17 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

18 
#ifndef NO_DUMMY_DECL 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

19 
struct internal_state {int dummy;}; /* for buggy compilers */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

20 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

21 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

22 
#ifndef Z_BUFSIZE 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

23 
# ifdef MAXSEG_64K 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

24 
# define Z_BUFSIZE 4096 /* minimize memory usage for 16bit DOS */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

25 
# else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

26 
# define Z_BUFSIZE 16384 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

27 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

28 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

29 
#ifndef Z_PRINTF_BUFSIZE 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

30 
# define Z_PRINTF_BUFSIZE 4096 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

31 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

32 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

33 
#ifdef __MVS__ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

34 
# pragma map (fdopen , "\174\174FDOPEN") 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

35 
FILE *fdopen(int, const char *); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

36 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

37 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

38 
#ifndef STDC 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

39 
extern voidp malloc OF((uInt size)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

40 
extern void free OF((voidpf ptr)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

41 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

42 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

43 
#define ALLOC(size) malloc(size) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

44 
#define TRYFREE(p) {if (p) free(p);} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

45 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

46 
static int const gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

47 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

48 
/* gzip flag byte */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

49 
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

50 
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

51 
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

52 
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

53 
#define COMMENT 0x10 /* bit 4 set: file comment present */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

54 
#define RESERVED 0xE0 /* bits 5..7: reserved */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

55 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

56 
typedef struct gz_stream { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

57 
z_stream stream; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

58 
int z_err; /* error code for last stream operation */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

59 
int z_eof; /* set if end of input file */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

60 
FILE *file; /* .gz file */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

61 
Byte *inbuf; /* input buffer */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

62 
Byte *outbuf; /* output buffer */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

63 
uLong crc; /* crc32 of uncompressed data */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

64 
char *msg; /* error message */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

65 
char *path; /* path name for debugging only */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

66 
int transparent; /* 1 if input file is not a .gz file */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

67 
char mode; /* 'w' or 'r' */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

68 
z_off_t start; /* start of compressed data in file (header skipped) */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

69 
z_off_t in; /* bytes into deflate or inflate */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

70 
z_off_t out; /* bytes out of deflate or inflate */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

71 
int back; /* one character pushback */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

72 
int last; /* true if pushback is last character */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

73 
} gz_stream; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

74 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

75 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

76 
local gzFile gz_open OF((const char *path, const char *mode, int fd)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

77 
local int do_flush OF((gzFile file, int flush)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

78 
local int get_byte OF((gz_stream *s)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

79 
local void check_header OF((gz_stream *s)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

80 
local int destroy OF((gz_stream *s)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

81 
local void putLong OF((FILE *file, uLong x)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

82 
local uLong getLong OF((gz_stream *s)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

83 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

84 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

85 
Opens a gzip (.gz) file for reading or writing. The mode parameter 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

86 
is as in fopen ("rb" or "wb"). The file is given either by file descriptor 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

87 
or path name (if fd == 1). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

88 
gz_open returns NULL if the file could not be opened or if there was 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

89 
insufficient memory to allocate the (de)compression state; errno 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

90 
can be checked to distinguish the two cases (if errno is zero, the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

91 
zlib error is Z_MEM_ERROR). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

92 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

93 
local gzFile gz_open (path, mode, fd) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

94 
const char *path; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

95 
const char *mode; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

96 
int fd; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

97 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

98 
int err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

99 
int level = Z_DEFAULT_COMPRESSION; /* compression level */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

100 
int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

101 
char *p = (char*)mode; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

102 
gz_stream *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

103 
char fmode[80]; /* copy of mode, without the compression level */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

104 
char *m = fmode; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

105 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

106 
if (!path  !mode) return Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

107 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

108 
s = (gz_stream *)ALLOC(sizeof(gz_stream)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

109 
if (!s) return Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

110 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

111 
s>stream.zalloc = (alloc_func)0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

112 
s>stream.zfree = (free_func)0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

113 
s>stream.opaque = (voidpf)0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

114 
s>stream.next_in = s>inbuf = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

115 
s>stream.next_out = s>outbuf = Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

116 
s>stream.avail_in = s>stream.avail_out = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

117 
s>file = NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

118 
s>z_err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

119 
s>z_eof = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

120 
s>in = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

121 
s>out = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

122 
s>back = EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

123 
s>crc = crc32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

124 
s>msg = NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

125 
s>transparent = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

126 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

127 
s>path = (char*)ALLOC(strlen(path)+1); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

128 
if (s>path == NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

129 
return destroy(s), (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

130 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

131 
strcpy(s>path, path); /* do this early for debugging */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

132 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

133 
s>mode = '\0'; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

134 
do { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

135 
if (*p == 'r') s>mode = 'r'; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

136 
if (*p == 'w'  *p == 'a') s>mode = 'w'; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

137 
if (*p >= '0' && *p <= '9') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

138 
level = *p  '0'; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

139 
} else if (*p == 'f') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

140 
strategy = Z_FILTERED; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

141 
} else if (*p == 'h') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

142 
strategy = Z_HUFFMAN_ONLY; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

143 
} else if (*p == 'R') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

144 
strategy = Z_RLE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

145 
} else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

146 
*m++ = *p; /* copy the mode */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

147 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

148 
} while (*p++ && m != fmode + sizeof(fmode)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

149 
if (s>mode == '\0') return destroy(s), (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

150 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

151 
if (s>mode == 'w') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

152 
#ifdef NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

153 
err = Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

154 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

155 
err = deflateInit2(&(s>stream), level, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

156 
Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, strategy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

157 
/* windowBits is passed < 0 to suppress zlib header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

158 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

159 
s>stream.next_out = s>outbuf = (Byte*)ALLOC(Z_BUFSIZE); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

160 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

161 
if (err != Z_OK  s>outbuf == Z_NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

162 
return destroy(s), (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

163 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

164 
} else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

165 
s>stream.next_in = s>inbuf = (Byte*)ALLOC(Z_BUFSIZE); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

166 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

167 
err = inflateInit2(&(s>stream), MAX_WBITS); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

168 
/* windowBits is passed < 0 to tell that there is no zlib header. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

169 
* Note that in this case inflate *requires* an extra "dummy" byte 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

170 
* after the compressed stream in order to complete decompression and 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

171 
* return Z_STREAM_END. Here the gzip CRC32 ensures that 4 bytes are 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

172 
* present after the compressed stream. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

173 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

174 
if (err != Z_OK  s>inbuf == Z_NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

175 
return destroy(s), (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

176 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

177 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

178 
s>stream.avail_out = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

179 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

180 
errno = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

181 
s>file = fd < 0 ? F_OPEN(path, fmode) : (FILE*)fdopen(fd, fmode); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

182 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

183 
if (s>file == NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

184 
return destroy(s), (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

185 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

186 
if (s>mode == 'w') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

187 
/* Write a very simple .gz header: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

188 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

189 
fprintf(s>file, "%c%c%c%c%c%c%c%c%c%c", gz_magic[0], gz_magic[1], 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

190 
Z_DEFLATED, 0 /*flags*/, 0,0,0,0 /*time*/, 0 /*xflags*/, OS_CODE); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

191 
s>start = 10L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

192 
/* We use 10L instead of ftell(s>file) to because ftell causes an 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

193 
* fflush on some systems. This version of the library doesn't use 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

194 
* start anyway in write mode, so this initialization is not 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

195 
* necessary. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

196 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

197 
} else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

198 
check_header(s); /* skip the .gz header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

199 
s>start = ftell(s>file)  s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

200 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

201 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

202 
return (gzFile)s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

203 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

204 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

205 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

206 
Opens a gzip (.gz) file for reading or writing. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

207 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

208 
gzFile ZEXPORT gzopen (path, mode) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

209 
const char *path; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

210 
const char *mode; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

211 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

212 
return gz_open (path, mode, 1); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

213 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

214 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

215 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

216 
Associate a gzFile with the file descriptor fd. fd is not dup'ed here 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

217 
to mimic the behavio(u)r of fdopen. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

218 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

219 
gzFile ZEXPORT gzdopen (fd, mode) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

220 
int fd; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

221 
const char *mode; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

222 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

223 
char name[20]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

224 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

225 
if (fd < 0) return (gzFile)Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

226 
sprintf(name, "<fd:%d>", fd); /* for debugging */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

227 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

228 
return gz_open (name, mode, fd); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

229 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

230 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

231 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

232 
* Update the compression level and strategy 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

233 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

234 
int ZEXPORT gzsetparams (file, level, strategy) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

235 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

236 
int level; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

237 
int strategy; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

238 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

239 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

240 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

241 
if (s == NULL  s>mode != 'w') return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

242 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

243 
/* Make room to allow flushing */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

244 
if (s>stream.avail_out == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

245 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

246 
s>stream.next_out = s>outbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

247 
if (fwrite(s>outbuf, 1, Z_BUFSIZE, s>file) != Z_BUFSIZE) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

248 
s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

249 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

250 
s>stream.avail_out = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

251 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

252 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

253 
return deflateParams (&(s>stream), level, strategy); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

254 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

255 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

256 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

257 
Read a byte from a gz_stream; update next_in and avail_in. Return EOF 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

258 
for end of file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

259 
IN assertion: the stream s has been sucessfully opened for reading. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

260 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

261 
local int get_byte(s) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

262 
gz_stream *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

263 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

264 
if (s>z_eof) return EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

265 
if (s>stream.avail_in == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

266 
errno = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

267 
s>stream.avail_in = fread(s>inbuf, 1, Z_BUFSIZE, s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

268 
if (s>stream.avail_in == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

269 
s>z_eof = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

270 
if (ferror(s>file)) s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

271 
return EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

272 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

273 
s>stream.next_in = s>inbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

274 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

275 
s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

276 
return *(s>stream.next_in)++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

277 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

278 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

279 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

280 
Check the gzip header of a gz_stream opened for reading. Set the stream 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

281 
mode to transparent if the gzip magic header is not present; set s>err 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

282 
to Z_DATA_ERROR if the magic header is present but the rest of the header 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

283 
is incorrect. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

284 
IN assertion: the stream s has already been created sucessfully; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

285 
s>stream.avail_in is zero for the first time, but may be nonzero 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

286 
for concatenated .gz files. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

287 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

288 
local void check_header(s) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

289 
gz_stream *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

290 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

291 
int method; /* method byte */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

292 
int flags; /* flags byte */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

293 
uInt len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

294 
int c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

295 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

296 
/* Assure two bytes in the buffer so we can peek ahead  handle case 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

297 
where first byte of header is at the end of the buffer after the last 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

298 
gzip segment */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

299 
len = s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

300 
if (len < 2) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

301 
if (len) s>inbuf[0] = s>stream.next_in[0]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

302 
errno = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

303 
len = fread(s>inbuf + len, 1, Z_BUFSIZE >> len, s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

304 
if (len == 0 && ferror(s>file)) s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

305 
s>stream.avail_in += len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

306 
s>stream.next_in = s>inbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

307 
if (s>stream.avail_in < 2) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

308 
s>transparent = s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

309 
return; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

310 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

311 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

312 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

313 
/* Peek ahead to check the gzip magic header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

314 
if (s>stream.next_in[0] != gz_magic[0]  
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

315 
s>stream.next_in[1] != gz_magic[1]) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

316 
s>transparent = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

317 
return; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

318 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

319 
s>stream.avail_in = 2; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

320 
s>stream.next_in += 2; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

321 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

322 
/* Check the rest of the gzip header */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

323 
method = get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

324 
flags = get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

325 
if (method != Z_DEFLATED  (flags & RESERVED) != 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

326 
s>z_err = Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

327 
return; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

328 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

329 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

330 
/* Discard time, xflags and OS code: */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

331 
for (len = 0; len < 6; len++) (void)get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

332 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

333 
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

334 
len = (uInt)get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

335 
len += ((uInt)get_byte(s))<<8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

336 
/* len is garbage if EOF but the loop below will quit anyway */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

337 
while (len != 0 && get_byte(s) != EOF) ; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

338 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

339 
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

340 
while ((c = get_byte(s)) != 0 && c != EOF) ; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

341 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

342 
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

343 
while ((c = get_byte(s)) != 0 && c != EOF) ; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

344 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

345 
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

346 
for (len = 0; len < 2; len++) (void)get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

347 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

348 
s>z_err = s>z_eof ? Z_DATA_ERROR : Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

349 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

350 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

351 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

352 
* Cleanup then free the given gz_stream. Return a zlib error code. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

353 
Try freeing in the reverse order of allocations. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

354 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

355 
local int destroy (s) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

356 
gz_stream *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

357 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

358 
int err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

359 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

360 
if (!s) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

361 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

362 
TRYFREE(s>msg); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

363 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

364 
if (s>stream.state != NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

365 
if (s>mode == 'w') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

366 
#ifdef NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

367 
err = Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

368 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

369 
err = deflateEnd(&(s>stream)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

370 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

371 
} else if (s>mode == 'r') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

372 
err = inflateEnd(&(s>stream)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

373 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

374 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

375 
if (s>file != NULL && fclose(s>file)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

376 
#ifdef ESPIPE 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

377 
if (errno != ESPIPE) /* fclose is broken for pipes in HP/UX */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

378 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

379 
err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

380 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

381 
if (s>z_err < 0) err = s>z_err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

382 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

383 
TRYFREE(s>inbuf); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

384 
TRYFREE(s>outbuf); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

385 
TRYFREE(s>path); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

386 
TRYFREE(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

387 
return err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

388 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

389 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

390 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

391 
Reads the given number of uncompressed bytes from the compressed file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

392 
gzread returns the number of bytes actually read (0 for end of file). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

393 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

394 
int ZEXPORT gzread (file, buf, len) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

395 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

396 
voidp buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

397 
unsigned len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

398 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

399 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

400 
Bytef *start = (Bytef*)buf; /* starting point for crc computation */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

401 
Byte *next_out; /* == stream.next_out but not forced far (for MSDOS) */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

402 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

403 
if (s == NULL  s>mode != 'r') return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

404 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

405 
if (s>z_err == Z_DATA_ERROR  s>z_err == Z_ERRNO) return 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

406 
if (s>z_err == Z_STREAM_END) return 0; /* EOF */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

407 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

408 
next_out = (Byte*)buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

409 
s>stream.next_out = (Bytef*)buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

410 
s>stream.avail_out = len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

411 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

412 
if (s>stream.avail_out && s>back != EOF) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

413 
*next_out++ = s>back; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

414 
s>stream.next_out++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

415 
s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

416 
s>back = EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

417 
s>out++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

418 
if (s>last) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

419 
s>z_err = Z_STREAM_END; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

420 
return 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

421 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

422 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

423 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

424 
while (s>stream.avail_out != 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

425 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

426 
if (s>transparent) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

427 
/* Copy first the lookahead bytes: */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

428 
uInt n = s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

429 
if (n > s>stream.avail_out) n = s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

430 
if (n > 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

431 
zmemcpy(s>stream.next_out, s>stream.next_in, n); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

432 
next_out += n; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

433 
s>stream.next_out = next_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

434 
s>stream.next_in += n; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

435 
s>stream.avail_out = n; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

436 
s>stream.avail_in = n; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

437 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

438 
if (s>stream.avail_out > 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

439 
s>stream.avail_out = fread(next_out, 1, s>stream.avail_out, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

440 
s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

441 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

442 
len = s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

443 
s>in += len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

444 
s>out += len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

445 
if (len == 0) s>z_eof = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

446 
return (int)len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

447 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

448 
if (s>stream.avail_in == 0 && !s>z_eof) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

449 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

450 
errno = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

451 
s>stream.avail_in = fread(s>inbuf, 1, Z_BUFSIZE, s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

452 
if (s>stream.avail_in == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

453 
s>z_eof = 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

454 
if (ferror(s>file)) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

455 
s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

456 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

457 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

458 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

459 
s>stream.next_in = s>inbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

460 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

461 
s>in += s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

462 
s>out += s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

463 
s>z_err = inflate(&(s>stream), Z_NO_FLUSH); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

464 
s>in = s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

465 
s>out = s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

466 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

467 
if (s>z_err == Z_STREAM_END) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

468 
/* Check CRC and original size */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

469 
s>crc = crc32(s>crc, start, (uInt)(s>stream.next_out  start)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

470 
start = s>stream.next_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

471 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

472 
if (getLong(s) != s>crc) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

473 
s>z_err = Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

474 
} else { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

475 
(void)getLong(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

476 
/* The uncompressed length returned by above getlong() may be 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

477 
* different from s>out in case of concatenated .gz files. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

478 
* Check for such files: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

479 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

480 
check_header(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

481 
if (s>z_err == Z_OK) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

482 
inflateReset(&(s>stream)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

483 
s>crc = crc32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

484 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

485 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

486 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

487 
if (s>z_err != Z_OK  s>z_eof) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

488 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

489 
s>crc = crc32(s>crc, start, (uInt)(s>stream.next_out  start)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

490 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

491 
return (int)(len  s>stream.avail_out); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

492 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

493 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

494 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

495 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

496 
Reads one byte from the compressed file. gzgetc returns this byte 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

497 
or 1 in case of end of file or error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

498 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

499 
int ZEXPORT gzgetc(file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

500 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

501 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

502 
unsigned char c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

503 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

504 
return gzread(file, &c, 1) == 1 ? c : 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

505 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

506 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

507 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

508 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

509 
Push one byte back onto the stream. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

510 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

511 
int ZEXPORT gzungetc(c, file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

512 
int c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

513 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

514 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

515 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

516 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

517 
if (s == NULL  s>mode != 'r'  c == EOF  s>back != EOF) return EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

518 
s>back = c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

519 
s>out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

520 
s>last = (s>z_err == Z_STREAM_END); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

521 
if (s>last) s>z_err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

522 
s>z_eof = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

523 
return c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

524 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

525 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

526 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

527 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

528 
Reads bytes from the compressed file until len1 characters are 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

529 
read, or a newline character is read and transferred to buf, or an 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

530 
endoffile condition is encountered. The string is then terminated 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

531 
with a null character. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

532 
gzgets returns buf, or Z_NULL in case of error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

533 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

534 
The current implementation is not optimized at all. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

535 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

536 
char * ZEXPORT gzgets(file, buf, len) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

537 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

538 
char *buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

539 
int len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

540 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

541 
char *b = buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

542 
if (buf == Z_NULL  len <= 0) return Z_NULL; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

543 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

544 
while (len > 0 && gzread(file, buf, 1) == 1 && *buf++ != '\n') ; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

545 
*buf = '\0'; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

546 
return b == buf && len > 0 ? Z_NULL : b; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

547 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

548 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

549 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

550 
#ifndef NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

551 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

552 
Writes the given number of uncompressed bytes into the compressed file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

553 
gzwrite returns the number of bytes actually written (0 in case of error). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

554 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

555 
int ZEXPORT gzwrite (file, buf, len) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

556 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

557 
voidpc buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

558 
unsigned len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

559 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

560 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

561 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

562 
if (s == NULL  s>mode != 'w') return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

563 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

564 
s>stream.next_in = (Bytef*)buf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

565 
s>stream.avail_in = len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

566 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

567 
while (s>stream.avail_in != 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

568 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

569 
if (s>stream.avail_out == 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

570 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

571 
s>stream.next_out = s>outbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

572 
if (fwrite(s>outbuf, 1, Z_BUFSIZE, s>file) != Z_BUFSIZE) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

573 
s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

574 
break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

575 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

576 
s>stream.avail_out = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

577 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

578 
s>in += s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

579 
s>out += s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

580 
s>z_err = deflate(&(s>stream), Z_NO_FLUSH); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

581 
s>in = s>stream.avail_in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

582 
s>out = s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

583 
if (s>z_err != Z_OK) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

584 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

585 
s>crc = crc32(s>crc, (const Bytef *)buf, len); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

586 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

587 
return (int)(len  s>stream.avail_in); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

588 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

589 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

590 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

591 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

592 
Converts, formats, and writes the args to the compressed file under 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

593 
control of the format string, as in fprintf. gzprintf returns the number of 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

594 
uncompressed bytes actually written (0 in case of error). 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

595 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

596 
#ifdef STDC 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

597 
#include <stdarg.h> 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

598 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

599 
int ZEXPORTVA gzprintf (gzFile file, const char *format, /* args */ ...) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

600 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

601 
char buf[Z_PRINTF_BUFSIZE]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

602 
va_list va; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

603 
int len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

604 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

605 
buf[sizeof(buf)  1] = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

606 
va_start(va, format); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

607 
#ifdef NO_vsnprintf 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

608 
# ifdef HAS_vsprintf_void 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

609 
(void)vsprintf(buf, format, va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

610 
va_end(va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

611 
for (len = 0; len < sizeof(buf); len++) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

612 
if (buf[len] == 0) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

613 
# else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

614 
len = vsprintf(buf, format, va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

615 
va_end(va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

616 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

617 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

618 
# ifdef HAS_vsnprintf_void 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

619 
(void)vsnprintf(buf, sizeof(buf), format, va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

620 
va_end(va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

621 
len = strlen(buf); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

622 
# else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

623 
len = vsnprintf(buf, sizeof(buf), format, va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

624 
va_end(va); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

625 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

626 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

627 
if (len <= 0  len >= (int)sizeof(buf)  buf[sizeof(buf)  1] != 0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

628 
return 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

629 
return gzwrite(file, buf, (unsigned)len); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

630 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

631 
#else /* not ANSI C */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

632 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

633 
int ZEXPORTVA gzprintf (file, format, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

634 
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

635 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

636 
const char *format; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

637 
int a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

638 
a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

639 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

640 
char buf[Z_PRINTF_BUFSIZE]; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

641 
int len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

642 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

643 
buf[sizeof(buf)  1] = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

644 
#ifdef NO_snprintf 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

645 
# ifdef HAS_sprintf_void 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

646 
sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

647 
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

648 
for (len = 0; len < sizeof(buf); len++) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

649 
if (buf[len] == 0) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

650 
# else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

651 
len = sprintf(buf, format, a1, a2, a3, a4, a5, a6, a7, a8, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

652 
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

653 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

654 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

655 
# ifdef HAS_snprintf_void 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

656 
snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

657 
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

658 
len = strlen(buf); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

659 
# else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

660 
len = snprintf(buf, sizeof(buf), format, a1, a2, a3, a4, a5, a6, a7, a8, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

661 
a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

662 
# endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

663 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

664 
if (len <= 0  len >= sizeof(buf)  buf[sizeof(buf)  1] != 0) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

665 
return 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

666 
return gzwrite(file, buf, len); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

667 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

668 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

669 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

670 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

671 
Writes c, converted to an unsigned char, into the compressed file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

672 
gzputc returns the value that was written, or 1 in case of error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

673 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

674 
int ZEXPORT gzputc(file, c) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

675 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

676 
int c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

677 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

678 
unsigned char cc = (unsigned char) c; /* required for big endian systems */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

679 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

680 
return gzwrite(file, &cc, 1) == 1 ? (int)cc : 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

681 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

682 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

683 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

684 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

685 
Writes the given nullterminated string to the compressed file, excluding 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

686 
the terminating null character. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

687 
gzputs returns the number of characters written, or 1 in case of error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

688 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

689 
int ZEXPORT gzputs(file, s) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

690 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

691 
const char *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

692 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

693 
return gzwrite(file, (char*)s, (unsigned)strlen(s)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

694 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

695 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

696 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

697 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

698 
Flushes all pending output into the compressed file. The parameter 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

699 
flush is as in the deflate() function. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

700 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

701 
local int do_flush (file, flush) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

702 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

703 
int flush; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

704 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

705 
uInt len; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

706 
int done = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

707 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

708 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

709 
if (s == NULL  s>mode != 'w') return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

710 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

711 
s>stream.avail_in = 0; /* should be zero already anyway */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

712 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

713 
for (;;) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

714 
len = Z_BUFSIZE  s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

715 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

716 
if (len != 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

717 
if ((uInt)fwrite(s>outbuf, 1, len, s>file) != len) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

718 
s>z_err = Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

719 
return Z_ERRNO; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

720 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

721 
s>stream.next_out = s>outbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

722 
s>stream.avail_out = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

723 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

724 
if (done) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

725 
s>out += s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

726 
s>z_err = deflate(&(s>stream), flush); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

727 
s>out = s>stream.avail_out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

728 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

729 
/* Ignore the second of two consecutive flushes: */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

730 
if (len == 0 && s>z_err == Z_BUF_ERROR) s>z_err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

731 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

732 
/* deflate has finished flushing only when it hasn't used up 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

733 
* all the available space in the output buffer: 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

734 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

735 
done = (s>stream.avail_out != 0  s>z_err == Z_STREAM_END); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

736 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

737 
if (s>z_err != Z_OK && s>z_err != Z_STREAM_END) break; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

738 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

739 
return s>z_err == Z_STREAM_END ? Z_OK : s>z_err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

740 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

741 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

742 
int ZEXPORT gzflush (file, flush) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

743 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

744 
int flush; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

745 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

746 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

747 
int err = do_flush (file, flush); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

748 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

749 
if (err) return err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

750 
fflush(s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

751 
return s>z_err == Z_STREAM_END ? Z_OK : s>z_err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

752 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

753 
#endif /* NO_GZCOMPRESS */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

754 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

755 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

756 
Sets the starting position for the next gzread or gzwrite on the given 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

757 
compressed file. The offset represents a number of bytes in the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

758 
gzseek returns the resulting offset location as measured in bytes from 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

759 
the beginning of the uncompressed stream, or 1 in case of error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

760 
SEEK_END is not implemented, returns error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

761 
In this version of the library, gzseek can be extremely slow. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

762 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

763 
z_off_t ZEXPORT gzseek (file, offset, whence) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

764 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

765 
z_off_t offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

766 
int whence; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

767 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

768 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

769 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

770 
if (s == NULL  whence == SEEK_END  
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

771 
s>z_err == Z_ERRNO  s>z_err == Z_DATA_ERROR) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

772 
return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

773 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

774 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

775 
if (s>mode == 'w') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

776 
#ifdef NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

777 
return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

778 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

779 
if (whence == SEEK_SET) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

780 
offset = s>in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

781 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

782 
if (offset < 0) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

783 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

784 
/* At this point, offset is the number of zero bytes to write. */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

785 
if (s>inbuf == Z_NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

786 
s>inbuf = (Byte*)ALLOC(Z_BUFSIZE); /* for seeking */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

787 
if (s>inbuf == Z_NULL) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

788 
zmemzero(s>inbuf, Z_BUFSIZE); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

789 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

790 
while (offset > 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

791 
uInt size = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

792 
if (offset < Z_BUFSIZE) size = (uInt)offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

793 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

794 
size = gzwrite(file, s>inbuf, size); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

795 
if (size == 0) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

796 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

797 
offset = size; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

798 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

799 
return s>in; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

800 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

801 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

802 
/* Rest of function is for reading only */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

803 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

804 
/* compute absolute position */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

805 
if (whence == SEEK_CUR) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

806 
offset += s>out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

807 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

808 
if (offset < 0) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

809 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

810 
if (s>transparent) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

811 
/* map to fseek */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

812 
s>back = EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

813 
s>stream.avail_in = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

814 
s>stream.next_in = s>inbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

815 
if (fseek(s>file, offset, SEEK_SET) < 0) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

816 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

817 
s>in = s>out = offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

818 
return offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

819 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

820 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

821 
/* For a negative seek, rewind and use positive seek */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

822 
if (offset >= s>out) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

823 
offset = s>out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

824 
} else if (gzrewind(file) < 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

825 
return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

826 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

827 
/* offset is now the number of bytes to skip. */ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

828 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

829 
if (offset != 0 && s>outbuf == Z_NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

830 
s>outbuf = (Byte*)ALLOC(Z_BUFSIZE); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

831 
if (s>outbuf == Z_NULL) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

832 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

833 
if (offset && s>back != EOF) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

834 
s>back = EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

835 
s>out++; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

836 
offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

837 
if (s>last) s>z_err = Z_STREAM_END; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

838 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

839 
while (offset > 0) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

840 
int size = Z_BUFSIZE; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

841 
if (offset < Z_BUFSIZE) size = (int)offset; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

842 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

843 
size = gzread(file, s>outbuf, (uInt)size); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

844 
if (size <= 0) return 1L; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

845 
offset = size; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

846 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

847 
return s>out; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

848 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

849 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

850 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

851 
Rewinds input file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

852 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

853 
int ZEXPORT gzrewind (file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

854 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

855 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

856 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

857 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

858 
if (s == NULL  s>mode != 'r') return 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

859 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

860 
s>z_err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

861 
s>z_eof = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

862 
s>back = EOF; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

863 
s>stream.avail_in = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

864 
s>stream.next_in = s>inbuf; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

865 
s>crc = crc32(0L, Z_NULL, 0); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

866 
if (!s>transparent) (void)inflateReset(&s>stream); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

867 
s>in = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

868 
s>out = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

869 
return fseek(s>file, s>start, SEEK_SET); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

870 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

871 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

872 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

873 
Returns the starting position for the next gzread or gzwrite on the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

874 
given compressed file. This position represents a number of bytes in the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

875 
uncompressed data stream. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

876 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

877 
z_off_t ZEXPORT gztell (file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

878 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

879 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

880 
return gzseek(file, 0L, SEEK_CUR); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

881 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

882 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

883 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

884 
Returns 1 when EOF has previously been detected reading the given 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

885 
input stream, otherwise zero. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

886 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

887 
int ZEXPORT gzeof (file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

888 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

889 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

890 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

891 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

892 
/* With concatenated compressed files that can have embedded 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

893 
* crc trailers, z_eof is no longer the only/best indicator of EOF 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

894 
* on a gz_stream. Handle endofstream error explicitly here. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

895 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

896 
if (s == NULL  s>mode != 'r') return 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

897 
if (s>z_eof) return 1; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

898 
return s>z_err == Z_STREAM_END; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

899 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

900 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

901 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

902 
Outputs a long in LSB order to the given file 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

903 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

904 
local void putLong (file, x) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

905 
FILE *file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

906 
uLong x; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

907 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

908 
int n; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

909 
for (n = 0; n < 4; n++) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

910 
fputc((int)(x & 0xff), file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

911 
x >>= 8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

912 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

913 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

914 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

915 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

916 
Reads a long in LSB order from the given gz_stream. Sets z_err in case 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

917 
of error. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

918 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

919 
local uLong getLong (s) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

920 
gz_stream *s; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

921 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

922 
uLong x = (uLong)get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

923 
int c; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

924 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

925 
x += ((uLong)get_byte(s))<<8; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

926 
x += ((uLong)get_byte(s))<<16; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

927 
c = get_byte(s); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

928 
if (c == EOF) s>z_err = Z_DATA_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

929 
x += ((uLong)c)<<24; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

930 
return x; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

931 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

932 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

933 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

934 
Flushes all pending output if necessary, closes the compressed file 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

935 
and deallocates all the (de)compression state. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

936 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

937 
int ZEXPORT gzclose (file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

938 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

939 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

940 
int err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

941 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

942 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

943 
if (s == NULL) return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

944 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

945 
if (s>mode == 'w') { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

946 
#ifdef NO_GZCOMPRESS 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

947 
return Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

948 
#else 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

949 
err = do_flush (file, Z_FINISH); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

950 
if (err != Z_OK) return destroy((gz_stream*)file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

951 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

952 
putLong (s>file, s>crc); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

953 
putLong (s>file, (uLong)(s>in & 0xffffffff)); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

954 
#endif 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

955 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

956 
return destroy((gz_stream*)file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

957 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

958 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

959 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

960 
Returns the error message for the last error which occured on the 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

961 
given compressed file. errnum is set to zlib error number. If an 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

962 
error occured in the file system and not in the compression library, 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

963 
errnum is set to Z_ERRNO and the application may consult errno 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

964 
to get the exact error code. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

965 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

966 
const char * ZEXPORT gzerror (file, errnum) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

967 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

968 
int *errnum; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

969 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

970 
char *m; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

971 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

972 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

973 
if (s == NULL) { 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

974 
*errnum = Z_STREAM_ERROR; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

975 
return (const char*)ERR_MSG(Z_STREAM_ERROR); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

976 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

977 
*errnum = s>z_err; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

978 
if (*errnum == Z_OK) return (const char*)""; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

979 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

980 
m = (char*)(*errnum == Z_ERRNO ? zstrerror(errno) : s>stream.msg); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

981 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

982 
if (m == NULL  *m == '\0') m = (char*)ERR_MSG(s>z_err); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

983 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

984 
TRYFREE(s>msg); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

985 
s>msg = (char*)ALLOC(strlen(s>path) + strlen(m) + 3); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

986 
if (s>msg == Z_NULL) return (const char*)ERR_MSG(Z_MEM_ERROR); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

987 
strcpy(s>msg, s>path); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

988 
strcat(s>msg, ": "); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

989 
strcat(s>msg, m); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

990 
return (const char*)s>msg; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

991 
} 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

992 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

993 
/* =========================================================================== 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

994 
Clear the error and endoffile flags, and do the same for the real file. 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

995 
*/ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

996 
void ZEXPORT gzclearerr (file) 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

997 
gzFile file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

998 
{ 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

999 
gz_stream *s = (gz_stream*)file; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1000 

691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1001 
if (s == NULL) return; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1002 
if (s>z_err != Z_STREAM_END) s>z_err = Z_OK; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1003 
s>z_eof = 0; 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1004 
clearerr(s>file); 
691c1eadb8b7
Upgraded internal zlib to 1.2.1 (thanks, Adam!)
Ryan C. Gordon <icculus@icculus.org>
parents:
diff
changeset

1005 
} 