/* 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
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
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;
if (zr == NULL)
return;
- if (zr->fr != NULL)
- fclose (zr->fr);
-
+ fclose (zr->fr);
free (zr->filename);
for (i = 0; i < zr->n_members; ++i)
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;
zr->nm = 0;
- zr->fr = fopen (filename, "r");
+ zr->fr = fopen (filename, "rb");
if (NULL == zr->fr)
{
ds_put_cstr (zr->errs, strerror (errno));
uint32_t ucomp_size, comp_size;
uint32_t crc;
-
+ bool new_member = false;
char *name = NULL;
int i;
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
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;
do
{
- fread (&byte, 1, 1, fp);
+ if (1 != fread (&byte, 1, 1, fp))
+ break;
if ( byte == seq[state])
state++;