diff --git a/src/libpspp/zip-reader.c b/src/libpspp/zip-reader.c index 34905b9..72cdd6d 100644 --- a/src/libpspp/zip-reader.c +++ b/src/libpspp/zip-reader.c @@ -324,6 +324,8 @@ zip_reader_create (const char *filename, struct string *errs) return NULL; } + printf ("%s:%d Found EOCD at 0x%08x\n", __FILE__, __LINE__, offset); + if ( 0 != fseeko (zr->fr, offset, SEEK_SET)) { const char *mm = strerror (errno); @@ -333,6 +335,7 @@ zip_reader_create (const char *filename, struct string *errs) return NULL; } + printf ("%s:%d Checking for EOCD at 0x%08x\n", __FILE__, __LINE__, offset); if ( ! check_magic (zr->fr, MAGIC_EOCD, zr->errs)) { @@ -513,6 +516,8 @@ find_eocd (FILE *fp, off_t *off) stop = start + sizeof (magic); do { + printf ("%s:%d Looking for EOCD starting at 0x%08x\n", __FILE__, __LINE__, start); + found = probe_magic (fp, magic, start, stop, off); /* FIXME: For extra confidence lookup the directory start record here*/ if ( start == 0) @@ -539,11 +544,15 @@ probe_magic (FILE *fp, uint32_t magic, off_t start, off_t stop, off_t *off) unsigned char seq[4]; unsigned char byte; + printf ("%s:%d Seeking to 0x%08x\n", __FILE__, __LINE__, start); + if ( 0 > fseeko (fp, start, SEEK_SET)) { return -1; } + printf ("%s:%d ftello says 0x%08x\n", __FILE__, __LINE__, ftello (fp)); + for (i = 0; i < 4 ; ++i) { seq[i] = (magic >> i * 8) & 0xFF; @@ -552,6 +561,7 @@ probe_magic (FILE *fp, uint32_t magic, off_t start, off_t stop, off_t *off) do { fread (&byte, 1, 1, fp); + printf ("%s:%d read one byte. State: %d ftello 0x%08x\n", __FILE__, __LINE__, state, ftello (fp)); if ( byte == seq[state]) state++; @@ -561,6 +571,7 @@ probe_magic (FILE *fp, uint32_t magic, off_t start, off_t stop, off_t *off) if ( state == 4) { *off = ftello (fp) - 4; + printf ("%s:%d returning offset 0x%08x\n", __FILE__, __LINE__, *off); return true; } start++;