Merge master into gtk3.
[pspp] / src / libpspp / zip-reader.c
index 985b0a9027723180f6362d430ad66e9b8f49c045..34905b9fb2cc2e9ab40ee0e0932c8127d4013a7e 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 2011 Free Software Foundation, Inc.
+   Copyright (C) 2011, 2013 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;
@@ -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;