summaryrefslogtreecommitdiff
path: root/gzio.c
diff options
context:
space:
mode:
Diffstat (limited to 'gzio.c')
-rw-r--r--gzio.c26
1 files changed, 17 insertions, 9 deletions
diff --git a/gzio.c b/gzio.c
index 365b6f5..6c3211a 100644
--- a/gzio.c
+++ b/gzio.c
@@ -3,7 +3,7 @@
3 * For conditions of distribution and use, see copyright notice in zlib.h 3 * For conditions of distribution and use, see copyright notice in zlib.h
4 */ 4 */
5 5
6/* $Id: gzio.c,v 1.4 1995/04/14 14:50:52 jloup Exp $ */ 6/* $Id: gzio.c,v 1.5 1995/04/29 17:13:56 jloup Exp $ */
7 7
8#include <stdio.h> 8#include <stdio.h>
9 9
@@ -46,7 +46,12 @@ typedef struct gz_stream {
46} gz_stream; 46} gz_stream;
47 47
48 48
49/* =========================================================================== 49local int destroy __P((gz_stream *s));
50local gzFile gz_open __P((char *path, char *mode, int fd));
51local void putLong __P((FILE *file, uLong x));
52local uLong getLong __P((Byte *buf));
53
54 /* ===========================================================================
50 * Cleanup then free the given gz_stream. Return a zlib error code. 55 * Cleanup then free the given gz_stream. Return a zlib error code.
51 */ 56 */
52local int destroy (s) 57local int destroy (s)
@@ -339,7 +344,7 @@ int gzflush (file, flush)
339 if (len != 0) { 344 if (len != 0) {
340 if (fwrite(s->outbuf, 1, len, s->file) != len) { 345 if (fwrite(s->outbuf, 1, len, s->file) != len) {
341 s->z_err = Z_ERRNO; 346 s->z_err = Z_ERRNO;
342 break; 347 return Z_ERRNO;
343 } 348 }
344 s->stream.next_out = s->outbuf; 349 s->stream.next_out = s->outbuf;
345 s->stream.avail_out = Z_BUFSIZE; 350 s->stream.avail_out = Z_BUFSIZE;
@@ -347,14 +352,14 @@ int gzflush (file, flush)
347 if (done) break; 352 if (done) break;
348 s->z_err = deflate(&(s->stream), flush); 353 s->z_err = deflate(&(s->stream), flush);
349 354
350 if (s->z_err != Z_OK) break; 355 /* deflate has finished flushing only when it hasn't used up
351
352 /* deflate has finished flushing only when it hasn't used up
353 * all the available space in the output buffer: 356 * all the available space in the output buffer:
354 */ 357 */
355 done = (s->stream.avail_out != 0); 358 done = (s->stream.avail_out != 0 || s->z_err == Z_STREAM_END);
359
360 if (s->z_err != Z_OK && s->z_err != Z_STREAM_END) break;
356 } 361 }
357 return s->z_err; 362 return s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
358} 363}
359 364
360/* =========================================================================== 365/* ===========================================================================
@@ -395,12 +400,15 @@ int gzclose (file)
395 gzFile file; 400 gzFile file;
396{ 401{
397 uInt n; 402 uInt n;
403 int err;
398 gz_stream *s = (gz_stream*)file; 404 gz_stream *s = (gz_stream*)file;
399 405
400 if (s == NULL) return Z_STREAM_ERROR; 406 if (s == NULL) return Z_STREAM_ERROR;
401 407
402 if (s->mode == 'w') { 408 if (s->mode == 'w') {
403 gzflush (file, Z_FINISH); 409 err = gzflush (file, Z_FINISH);
410 if (err != Z_OK) return destroy(file);
411
404 putLong (s->file, s->crc); 412 putLong (s->file, s->crc);
405 putLong (s->file, s->stream.total_in); 413 putLong (s->file, s->stream.total_in);
406 414