Zip Reader: Take members from the index if they exist.
authorJohn Darrington <john@darrington.wattle.id.au>
Mon, 18 Feb 2013 08:35:53 +0000 (09:35 +0100)
committerJohn Darrington <john@darrington.wattle.id.au>
Mon, 18 Feb 2013 20:59:06 +0000 (21:59 +0100)
This allows readers to be iterated more than once.

src/libpspp/zip-reader.c

index 4672a1079f96ae12367670c7a1d4a760425c251b..59c47bc97507e78d6e716c46288458d796a8eb53 100644 (file)
@@ -390,17 +390,15 @@ zip_member_open (struct zip_reader *zr, const char *member)
   if ( zr == NULL)
     return NULL;
 
-  for (i = 0 ; i < zr->n_members; ++i)
+  for (i = 0; i < zr->n_members; ++i)
   {
-    zm = zr->members[i] = zip_header_read_next (zr);
+    zm = zr->members[i];
+    if (zm == NULL)
+      zm = zr->members[i] = zip_header_read_next (zr);
     if (zm && 0 == strcmp (zm->name, member))
-      {
-       break;
-      }
+      break;
     else
-      {
-       zm = NULL;
-      }
+      zm = NULL;
   }
   
   if ( zm == NULL)