X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flibpspp%2Fzip-reader.c;h=56a4c81019d620ce8c43627fa2101d348defc1d4;hb=ad9374fb26300c7d6c72b358b6ee9f0b6e5b5c87;hp=985b0a9027723180f6362d430ad66e9b8f49c045;hpb=57531cdd0b00b297859d70b3c8ea8fcd4ba5acbd;p=pspp diff --git a/src/libpspp/zip-reader.c b/src/libpspp/zip-reader.c index 985b0a9027..56a4c81019 100644 --- a/src/libpspp/zip-reader.c +++ b/src/libpspp/zip-reader.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2011 Free Software Foundation, Inc. + Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -65,9 +65,7 @@ stored_finish (struct zip_member *zm UNUSED) static struct decompressor decompressors[n_COMPRESSION] = { {stored_init, stored_read, stored_finish}, -#if HAVE_ZLIB_H {inflate_init, inflate_read, inflate_finish} -#endif }; static enum compression @@ -79,11 +77,9 @@ comp_code (struct zip_member *zm, uint16_t c) case 0: which = COMPRESSION_STORED; break; -#if HAVE_ZLIB_H case 8: which = COMPRESSION_INFLATE; break; -#endif default: ds_put_format (zm->errs, _("Unsupported compression type (%d)"), c); which = n_COMPRESSION; @@ -282,7 +278,7 @@ zip_header_read_next (struct zip_reader *zr) zr->members[zr->nm++] = zm; - zm->fp = fopen (zr->filename, "r"); + zm->fp = fopen (zr->filename, "rb"); zm->ref_cnt = 1; zm->errs = zr->errs; @@ -305,7 +301,7 @@ zip_reader_create (const char *filename, struct string *errs) zr->nm = 0; - zr->fr = fopen (filename, "r"); + zr->fr = fopen (filename, "rb"); if (NULL == zr->fr) { ds_put_cstr (zr->errs, strerror (errno)); @@ -382,7 +378,7 @@ zip_member_open (struct zip_reader *zr, const char *member) uint32_t ucomp_size, comp_size; uint32_t crc; - + bool new_member = false; char *name = NULL; int i; @@ -396,7 +392,10 @@ zip_member_open (struct zip_reader *zr, const char *member) zm = zr->members[i]; if (zm == NULL) - zm = zr->members[i] = zip_header_read_next (zr); + { + zm = zr->members[i] = zip_header_read_next (zr); + new_member = true; + } if (zm && 0 == strcmp (zm->name, member)) break; else @@ -450,8 +449,11 @@ zip_member_open (struct zip_reader *zr, const char *member) free (name); zm->bytes_unread = zm->ucomp_size; + + if ( !new_member) + decompressors[zm->compression].finish (zm); - if ( ! decompressors[zm->compression].init (zm) ) + if (!decompressors[zm->compression].init (zm) ) return NULL; return zm; @@ -549,7 +551,8 @@ probe_magic (FILE *fp, uint32_t magic, off_t start, off_t stop, off_t *off) do { - fread (&byte, 1, 1, fp); + if (1 != fread (&byte, 1, 1, fp)) + break; if ( byte == seq[state]) state++;