aboutsummaryrefslogtreecommitdiff
path: root/gzlib.c
diff options
context:
space:
mode:
authorMark Adler <madler@alumni.caltech.edu>2025-05-11 14:49:04 -0700
committerMark Adler <git@madler.net>2025-12-06 17:39:14 -0800
commit1ab1026a20282383d9cd2282f81461655bea4028 (patch)
tree511ef0996f9beb4c83ba15e72d7cc62d6252bb56 /gzlib.c
parent473f78532aed8f5a8d55cd6e7b305160db9cf742 (diff)
downloadzlib-1ab1026a20282383d9cd2282f81461655bea4028.tar.gz
zlib-1ab1026a20282383d9cd2282f81461655bea4028.tar.bz2
zlib-1ab1026a20282383d9cd2282f81461655bea4028.zip
Add a "G" option to force gzip, disabling transparency in gzread().
If the input is not a gzip stream with this option, an error will be returned.
Diffstat (limited to 'gzlib.c')
-rw-r--r--gzlib.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/gzlib.c b/gzlib.c
index 2f9cdd4e..4c1aa83a 100644
--- a/gzlib.c
+++ b/gzlib.c
@@ -153,6 +153,9 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
153 case 'F': 153 case 'F':
154 state->strategy = Z_FIXED; 154 state->strategy = Z_FIXED;
155 break; 155 break;
156 case 'G':
157 state->direct = -1;
158 break;
156 case 'T': 159 case 'T':
157 state->direct = 1; 160 state->direct = 1;
158 break; 161 break;
@@ -168,14 +171,25 @@ local gzFile gz_open(const void *path, int fd, const char *mode) {
168 return NULL; 171 return NULL;
169 } 172 }
170 173
171 /* can't force transparent read */ 174 /* direct is 0, 1 if "T", or -1 if "G" (last "G" or "T" wins) */
172 if (state->mode == GZ_READ) { 175 if (state->mode == GZ_READ) {
173 if (state->direct) { 176 if (state->direct == 1) {
177 /* can't force a transparent read */
174 free(state); 178 free(state);
175 return NULL; 179 return NULL;
176 } 180 }
177 state->direct = 1; /* for empty file */ 181 if (state->direct == 0)
182 /* default when reading is auto-detect of gzip vs. transparent --
183 start with a transparent assumption in case of an empty file */
184 state->direct = 1;
185 }
186 else if (state->direct == -1) {
187 /* "G" has no meaning when writing -- disallow it */
188 free(state);
189 return NULL;
178 } 190 }
191 /* if reading, direct == 1 for auto-detect, -1 for gzip only; if writing or
192 appending, direct == 0 for gzip, 1 for transparent (copy in to out) */
179 193
180 /* save the path name for error messages */ 194 /* save the path name for error messages */
181#ifdef WIDECHAR 195#ifdef WIDECHAR