summaryrefslogtreecommitdiff
path: root/ext/zip/lib/zip_open.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/zip/lib/zip_open.c')
-rw-r--r--ext/zip/lib/zip_open.c84
1 files changed, 42 insertions, 42 deletions
diff --git a/ext/zip/lib/zip_open.c b/ext/zip/lib/zip_open.c
index d91fe469db..1acaefa30e 100644
--- a/ext/zip/lib/zip_open.c
+++ b/ext/zip/lib/zip_open.c
@@ -17,7 +17,7 @@
3. The names of the authors may not be used to endorse or promote
products derived from this software without specific prior
written permission.
-
+
THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -31,7 +31,7 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
+
#include <sys/stat.h>
#include <errno.h>
@@ -58,21 +58,21 @@ static struct zip_cdir *_zip_read_eocd(const unsigned char *, const unsigned cha
static struct zip_cdir *_zip_read_eocd64(FILE *, const unsigned char *, const unsigned char *,
off_t, size_t, unsigned int, struct zip_error *);
-
+
ZIP_EXTERN struct zip *
zip_open(const char *fn, int _flags, int *zep)
{
FILE *fp;
unsigned int flags;
-
+
if (_flags < 0) {
if (zep)
*zep = ZIP_ER_INVAL;
return NULL;
}
flags = (unsigned int)_flags;
-
+
switch (_zip_file_exists(fn, flags, zep)) {
case -1:
return NULL;
@@ -81,7 +81,7 @@ zip_open(const char *fn, int _flags, int *zep)
default:
if (flags & ZIP_TRUNCATE) {
FILE *f;
-
+
if ((f = fopen(fn, "rb")) == NULL) {
set_error(zep, NULL, ZIP_ER_OPEN);
return NULL;
@@ -105,7 +105,7 @@ ZIP_EXTERN int
zip_archive_set_tempdir(struct zip *za, const char *tempdir)
{
char *new_tempdir;
-
+
if (tempdir) {
if ((new_tempdir = strdup(tempdir)) == NULL) {
_zip_error_set(&za->error, ZIP_ER_MEMORY, errno);
@@ -114,13 +114,13 @@ zip_archive_set_tempdir(struct zip *za, const char *tempdir)
}
else
new_tempdir = NULL;
-
+
free(za->tempdir);
za->tempdir = new_tempdir;
-
+
return 0;
}
-
+
struct zip *
_zip_open(const char *fn, FILE *fp, unsigned int flags, int *zep)
@@ -160,7 +160,7 @@ _zip_open(const char *fn, FILE *fp, unsigned int flags, int *zep)
za->nentry = cdir->nentry;
za->nentry_alloc = cdir->nentry_alloc;
za->comment_orig = cdir->comment;
-
+
za->zp = fp;
_zip_check_torrentzip(za, cdir);
@@ -172,7 +172,7 @@ _zip_open(const char *fn, FILE *fp, unsigned int flags, int *zep)
return za;
}
-
+
static void
set_error(int *zep, const struct zip_error *err, int ze)
@@ -189,12 +189,12 @@ set_error(int *zep, const struct zip_error *err, int ze)
*zep = ze;
}
-
+
/* _zip_readcdir:
tries to find a valid end-of-central-directory at the beginning of
buf, and then the corresponding central directory entries.
- Returns a struct zip_cdir which contains the central directory
+ Returns a struct zip_cdir which contains the central directory
entries, or NULL if unsuccessful. */
static struct zip_cdir *
@@ -294,11 +294,11 @@ _zip_readcdir(FILE *fp, off_t buf_offset, unsigned char *buf, const unsigned cha
_zip_cdir_free(cd);
return NULL;
}
-
+
return cd;
}
-
+
/* _zip_checkcons:
Checks the consistency of the central directory by comparing central
@@ -327,7 +327,7 @@ _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
_zip_error_set(error, ZIP_ER_NOZIP, 0);
return -1;
}
-
+
j = cd->entry[i].orig->offset + cd->entry[i].orig->comp_size
+ _zip_string_length(cd->entry[i].orig->filename) + LENTRYSIZE;
if (j > max)
@@ -336,32 +336,32 @@ _zip_checkcons(FILE *fp, struct zip_cdir *cd, struct zip_error *error)
_zip_error_set(error, ZIP_ER_NOZIP, 0);
return -1;
}
-
+
if (fseeko(fp, (off_t)cd->entry[i].orig->offset, SEEK_SET) != 0) {
_zip_error_set(error, ZIP_ER_SEEK, errno);
return -1;
}
-
+
if (_zip_dirent_read(&temp, fp, NULL, NULL, 1, error) == -1)
return -1;
-
+
if (_zip_headercomp(cd->entry[i].orig, &temp) != 0) {
_zip_error_set(error, ZIP_ER_INCONS, 0);
_zip_dirent_finalize(&temp);
return -1;
}
-
+
cd->entry[i].orig->extra_fields = _zip_ef_merge(cd->entry[i].orig->extra_fields, temp.extra_fields);
cd->entry[i].orig->local_extra_fields_read = 1;
temp.extra_fields = NULL;
-
+
_zip_dirent_finalize(&temp);
}
return (max-min) < ZIP_INT64_MAX ? (zip_int64_t)(max-min) : ZIP_INT64_MAX;
}
-
+
/* _zip_check_torrentzip:
check whether ZA has a valid TORRENTZIP comment, i.e. is torrentzipped */
@@ -395,7 +395,7 @@ _zip_check_torrentzip(struct zip *za, const struct zip_cdir *cdir)
}
-
+
/* _zip_headercomp:
compares a central directory entry and a local file header
@@ -428,7 +428,7 @@ _zip_headercomp(const struct zip_dirent *central, const struct zip_dirent *local
return 0;
}
-
+
static struct zip *
_zip_allocate_new(const char *fn, unsigned int flags, int *zep)
@@ -455,7 +455,7 @@ _zip_allocate_new(const char *fn, unsigned int flags, int *zep)
return za;
}
-
+
static int
_zip_file_exists(const char *fn, unsigned int flags, int *zep)
@@ -466,7 +466,7 @@ _zip_file_exists(const char *fn, unsigned int flags, int *zep)
set_error(zep, NULL, ZIP_ER_INVAL);
return -1;
}
-
+
if (stat(fn, &st) != 0) {
if (flags & ZIP_CREATE)
return 0;
@@ -485,7 +485,7 @@ _zip_file_exists(const char *fn, unsigned int flags, int *zep)
return 1;
}
-
+
static struct zip_cdir *
_zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
@@ -502,7 +502,7 @@ _zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
set_error(zep, NULL, ZIP_ER_NOZIP);
return NULL;
}
-
+
i = fseeko(fp, -(len < CDBUFSIZE ? len : CDBUFSIZE), SEEK_END);
if (i == -1 && errno != EFBIG) {
/* seek before start of file on my machine */
@@ -510,7 +510,7 @@ _zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
return NULL;
}
buf_offset = ftello(fp);
-
+
/* 64k is too much for stack */
if ((buf=(unsigned char *)malloc(CDBUFSIZE)) == NULL) {
set_error(zep, NULL, ZIP_ER_MEMORY);
@@ -525,7 +525,7 @@ _zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
free(buf);
return NULL;
}
-
+
best = -1;
cdir = NULL;
match = buf+ (buflen < CDBUFSIZE ? 0 : EOCD64LOCLEN);
@@ -563,7 +563,7 @@ _zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
}
free(buf);
-
+
if (best < 0) {
set_error(zep, &zerr, 0);
_zip_cdir_free(cdir);
@@ -573,13 +573,13 @@ _zip_find_central_dir(FILE *fp, unsigned int flags, int *zep, off_t len)
return cdir;
}
-
+
static unsigned char *
_zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little, size_t littlelen)
{
const unsigned char *p;
-
+
if ((biglen < littlelen) || (littlelen == 0))
return NULL;
p = big-1;
@@ -592,7 +592,7 @@ _zip_memmem(const unsigned char *big, size_t biglen, const unsigned char *little
return NULL;
}
-
+
static struct zip_cdir *
_zip_read_eocd(const unsigned char *eocd, const unsigned char *buf, off_t buf_offset, size_t buflen,
@@ -626,7 +626,7 @@ _zip_read_eocd(const unsigned char *eocd, const unsigned char *buf, off_t buf_of
_zip_error_set(error, ZIP_ER_SEEK, EFBIG);
return NULL;
}
-
+
if (offset+size > (zip_uint64_t)(buf_offset + (eocd-buf))) {
/* cdir spans past EOCD record */
_zip_error_set(error, ZIP_ER_INCONS, 0);
@@ -643,11 +643,11 @@ _zip_read_eocd(const unsigned char *eocd, const unsigned char *buf, off_t buf_of
cd->size = (off_t)size;
cd->offset = (off_t)offset;
-
+
return cd;
}
-
+
static struct zip_cdir *
_zip_read_eocd64(FILE *f, const zip_uint8_t *eocd64loc, const zip_uint8_t *buf,
@@ -662,7 +662,7 @@ _zip_read_eocd64(FILE *f, const zip_uint8_t *eocd64loc, const zip_uint8_t *buf,
cdp = eocd64loc+8;
eocd_offset = _zip_read8(&cdp);
-
+
if (eocd_offset > ZIP_OFF_MAX || eocd_offset + EOCD64LEN > ZIP_OFF_MAX) {
_zip_error_set(error, ZIP_ER_SEEK, EFBIG);
return NULL;
@@ -700,7 +700,7 @@ _zip_read_eocd64(FILE *f, const zip_uint8_t *eocd64loc, const zip_uint8_t *buf,
return NULL;
}
cdp += 4;
-
+
size = _zip_read8(&cdp);
if ((flags & ZIP_CHECKCONS) && size+eocd_offset+12 != (zip_uint64_t)(buf_offset+(eocd64loc-buf))) {
@@ -710,7 +710,7 @@ _zip_read_eocd64(FILE *f, const zip_uint8_t *eocd64loc, const zip_uint8_t *buf,
cdp += 4; /* skip version made by/needed */
cdp += 8; /* skip num disks */
-
+
nentry = _zip_read8(&cdp);
i = _zip_read8(&cdp);
@@ -734,7 +734,7 @@ _zip_read_eocd64(FILE *f, const zip_uint8_t *eocd64loc, const zip_uint8_t *buf,
if ((cd=_zip_cdir_new(nentry, error)) == NULL)
return NULL;
-
+
cd->size = (off_t)size;
cd->offset = (off_t)offset;