From 26a99cd8957db86bdc75d9d1ebf00146cb20c87c Mon Sep 17 00:00:00 2001 From: Mark Adler Date: Sun, 2 Oct 2011 13:24:43 -0700 Subject: Add a transparent write mode to gzopen() when 'T' is in the mode. --- gzlib.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'gzlib.c') diff --git a/gzlib.c b/gzlib.c index 7b31d24..e53b6ab 100644 --- a/gzlib.c +++ b/gzlib.c @@ -79,7 +79,6 @@ local void gz_reset(state) if (state->mode == GZ_READ) { /* for reading ... */ state->eof = 0; /* not at end of file */ state->how = LOOK; /* look for gzip header */ - state->direct = 1; /* default for empty file */ } state->seek = 0; /* no seek request pending */ gz_error(state, Z_OK, NULL); /* clear error */ @@ -111,6 +110,7 @@ local gzFile gz_open(path, fd, mode) state->mode = GZ_NONE; state->level = Z_DEFAULT_COMPRESSION; state->strategy = Z_DEFAULT_STRATEGY; + state->direct = 0; while (*mode) { if (*mode >= '0' && *mode <= '9') state->level = *mode - '0'; @@ -143,6 +143,8 @@ local gzFile gz_open(path, fd, mode) break; case 'F': state->strategy = Z_FIXED; + case 'T': + state->direct = 1; default: /* could consider as an error, but just ignore */ ; } @@ -155,6 +157,15 @@ local gzFile gz_open(path, fd, mode) return NULL; } + /* can't force transparent read */ + if (state->mode == GZ_READ) { + if (state->direct) { + free(state); + return NULL; + } + state->direct = 1; /* for empty file */ + } + /* save the path name for error messages */ state->path = malloc(strlen(path) + 1); if (state->path == NULL) { -- cgit v1.2.3-55-g6feb