}
-static struct decompressor decompressors[n_COMPRESSION] =
+static struct decompressor decompressors[n_COMPRESSION] =
{
{stored_init, stored_read, stored_finish},
{inflate_init, inflate_read, inflate_finish}
comp_code (struct zip_member *zm, uint16_t c)
{
enum compression which;
+ assert (zm->errmsgs);
switch (c)
{
case 0:
which = COMPRESSION_INFLATE;
break;
default:
- ds_put_format (zm->errs, _("Unsupported compression type (%d)"), c);
+ ds_put_format (zm->errmsgs, _("Unsupported compression type (%d)"), c);
which = n_COMPRESSION;
break;
}
void
zip_member_finish (struct zip_member *zm)
{
- ds_clear (zm->errs);
+ ds_clear (zm->errmsgs);
/* Probably not useful, because we would have to read right to the end of the member
if (zm->expected_crc != zm->crc)
{
zip_reader_destroy (struct zip_reader *zr)
{
int i;
- if (zr == NULL)
+ if (zr == NULL)
return;
fclose (zr->fr);
/* Read N bytes from F, storing the result in X */
static bool
-get_bytes (FILE *f, void *x, size_t n)
+get_bytes (FILE *f, void *x, size_t n)
{
return (n == fread (x, 1, n, f));
}
if ((expected != magic))
{
ds_put_format (err,
- _("Corrupt file at 0x%llx: Expected %"PRIx32"; got %"PRIx32),
+ _("Corrupt file at 0x%llx: Expected %"PRIx32"; got %"PRIx32),
(long long int) ftello (f) - sizeof (uint32_t), expected, magic);
return false;
{
int bytes_read = 0;
- ds_clear (zm->errs);
+ ds_clear (zm->errmsgs);
if ( bytes > zm->bytes_unread)
bytes = zm->bytes_unread;
/*
Read a local file header from ZR and add it to ZR's internal array.
Returns a pointer to the member read. This pointer belongs to ZR.
- If the caller wishes to control it, she should ref it with
+ If the caller wishes to control it, she should ref it with
zip_member_ref.
*/
static struct zip_member *
uint16_t v, nlen, extralen;
uint16_t gp, time, date;
-
+
uint16_t clen, diskstart, iattr;
uint32_t eattr;
uint16_t comp_type;
ds_clear (zr->errs);
+ zm->errmsgs = zr->errs;
if ( ! check_magic (zr->fr, MAGIC_SOCD, zr->errs))
return NULL;
if (! get_bytes (zr->fr, zm->name, nlen)) return NULL;
skip_bytes (zr->fr, extralen);
-
+
zr->members[zr->nm++] = zm;
zm->fp = fopen (zr->filename, "rb");
zm->ref_cnt = 1;
- zm->errs = zr->errs;
+
return zm;
}
free (zr);
return NULL;
}
-
+
if (! get_u16 (zr->fr, &disknum)) return NULL;
if (! get_u16 (zr->fr, &disknum)) return NULL;
zr->members = xcalloc (zr->n_members, sizeof (*zr->members));
memset (zr->members, 0, zr->n_members * sizeof (*zr->members));
- zr->filename = strdup (filename);
+ zr->filename = xstrdup (filename);
return zr;
}
uint16_t v, nlen, extra_len;
uint16_t gp, comp_type, time, date;
uint32_t ucomp_size, comp_size;
-
+
uint32_t crc;
bool new_member = false;
char *name = NULL;
else
zm = NULL;
}
-
+
if ( zm == NULL)
return NULL;
if ( 0 != fseeko (zm->fp, zm->offset, SEEK_SET))
{
const char *mm = strerror (errno);
- ds_put_format (zm->errs, _("Failed to seek to start of member `%s': %s"), zm->name, mm);
+ ds_put_format (zm->errmsgs, _("Failed to seek to start of member `%s': %s"), zm->name, mm);
return NULL;
}
if (strcmp (name, zm->name) != 0)
{
- ds_put_format (zm->errs,
+ ds_put_format (zm->errmsgs,
_("Name mismatch in zip archive. Central directory says `%s'; local file header says `%s'"),
zm->name, name);
free (name);
free (name);
zm->bytes_unread = zm->ucomp_size;
-
+
if ( !new_member)
decompressors[zm->compression].finish (zm);
const uint32_t magic = MAGIC_EOCD;
bool found = false;
- /* The magic cannot be more than 22 bytes from the end of the file,
+ /* The magic cannot be more than 22 bytes from the end of the file,
because that is the minimum length of the EndOfCentralDirectory
record.
*/
}
start = ftello (fp);
stop = start + sizeof (magic);
- do
+ do
{
found = probe_magic (fp, magic, start, stop, off);
/* FIXME: For extra confidence lookup the directory start record here*/
state++;
else
state = 0;
-
+
if ( state == 4)
{
*off = ftello (fp) - 4;