fix compile errors introduced in last, more error handling cleanup

--HG--
branch : HEAD
diff --git a/TODO b/TODO
index 5953804..79236be 100644
--- a/TODO
+++ b/TODO
@@ -6,6 +6,7 @@
 	clean up error handling and error code setting (get rid of zip_err)
 	zip_{add,replace}*: don't use struct zip_meta
 	don't expose zip_free_meta, zip_meta_new
+	defines for compression method
 * documentation: zip_add*, zip_replace*, zip_{,_file}get_error,
 	zip_error_sys_type, zip_get_num_files, zip_error_str
 * regression tests
@@ -14,6 +15,7 @@
 ------------------------------------------------ others
 * fix warnings in zipcmp
 * zipcmp: add option for file content comparison
+* support for zip64 (large file)
 
 * don't allow the same filename twice in a zip (when adding/replacing)
 * append to files (for self-extracting files)
diff --git a/lib/zip_close.c b/lib/zip_close.c
index 12fd6f3..43e7bd5 100644
--- a/lib/zip_close.c
+++ b/lib/zip_close.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_close.c,v 1.35 2003/10/04 07:39:52 dillo Exp $
+  $NiH: zip_close.c,v 1.36 2003/10/06 16:37:40 dillo Exp $
 
   zip_close.c -- close zip archive and update changes
   Copyright (C) 1999 Dieter Baron and Thomas Klausner
@@ -125,22 +125,26 @@
     
     if ((tfp=fdopen(tfd, "r+b")) == NULL) {
 	_zip_error_set(&zf->error, ZERR_TMPOPEN, errno);
+	close(tfd);
 	remove(temp);
 	free(temp);
-	close(tfd);
 	return -1;
     }
 
-    tzf=_zip_new(); /* XXX: bail out if tzf == NULL */
+    if ((tzf=_zip_new(&zf->error.zip_err)) == NULL) {
+	fclose(tfp);
+	remove(temp);
+	free(temp);
+	return -1;
+    }
     tzf->zp = tfp;
     tzf->zn = temp;
-    tzf->nentry = 0;
-    tzf->entry = NULL;
-    tzf->nentry_alloc = 0;
     tzf->comlen = zf->comlen;
-    tzf->cd_size = tzf->cd_offset = 0;
-    tzf->com = (unsigned char *)_zip_memdup(zf->com, zf->comlen);
-    /* XXX: bail out if tzf->com == NULL; */
+    if ((tzf->com=(unsigned char *)_zip_memdup(zf->com, zf->comlen)) == NULL) {
+	_zip_error_set(&zf->error, ZERR_MEMORY, 0);
+	_zip_free(tzf);
+	return -1;
+    }
 
     count = 0;
     if (zf->entry) {
diff --git a/lib/zip_fopen_index.c b/lib/zip_fopen_index.c
index 51d663a..193d9b2 100644
--- a/lib/zip_fopen_index.c
+++ b/lib/zip_fopen_index.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_fopen_index.c,v 1.13 2003/10/03 11:20:16 dillo Exp $
+  $NiH: zip_fopen_index.c,v 1.14 2003/10/06 16:37:41 dillo Exp $
 
   zip_fopen_index.c -- open file in zip archive for reading by index
   Copyright (C) 1999 Dieter Baron and Thomas Klausner
@@ -35,6 +35,7 @@
 
 
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -175,7 +176,7 @@
 static struct zip_file *
 _zip_file_new(struct zip *zf)
 {
-    struct zip_file *zff, file;
+    struct zip_file *zff, **file;
     int n;
 
     if ((zff=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) {
diff --git a/lib/zip_free.c b/lib/zip_free.c
index e82a539..e927466 100644
--- a/lib/zip_free.c
+++ b/lib/zip_free.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_free.c,v 1.6 2003/10/02 14:13:30 dillo Exp $
+  $NiH: zip_free.c,v 1.7 2003/10/06 16:37:41 dillo Exp $
 
   zip_free.c -- free struct zip
   Copyright (C) 1999 Dieter Baron and Thomas Klausner
@@ -51,7 +51,7 @@
     int i;
 
     if (zf == NULL)
-	return 0;
+	return;
 
     if (zf->zn)
 	free(zf->zn);
diff --git a/lib/zip_new.c b/lib/zip_new.c
index d7f7e61..0c34f30 100644
--- a/lib/zip_new.c
+++ b/lib/zip_new.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_new.c,v 1.4 2003/03/16 10:21:40 wiz Exp $
+  $NiH: zip_new.c,v 1.5 2003/10/02 14:13:31 dillo Exp $
 
   zip_new.c -- create and init struct zip
   Copyright (C) 1999 Dieter Baron and Thomas Klausner
@@ -46,13 +46,14 @@
    the new struct. */
 
 struct zip *
-_zip_new(void)
+_zip_new(int *errp)
 {
     struct zip *zf;
 
     zf = (struct zip *)malloc(sizeof(struct zip));
     if (!zf) {
-	zip_err = ZERR_MEMORY;
+	if (errp)
+	    *errp = ZERR_MEMORY;
 	return NULL;
     }
 
diff --git a/lib/zip_open.c b/lib/zip_open.c
index cf336c3..163ef28 100644
--- a/lib/zip_open.c
+++ b/lib/zip_open.c
@@ -1,5 +1,5 @@
 /*
-  $NiH: zip_open.c,v 1.17 2003/10/06 02:50:06 dillo Exp $
+  $NiH: zip_open.c,v 1.18 2003/10/06 16:37:41 dillo Exp $
 
   zip_open.c -- open zip archive
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
@@ -48,7 +48,7 @@
 
 static void set_error(int *errp, int err);
 static struct zip *_zip_readcdir(FILE *fp, unsigned char *buf,
-			   unsigned char *eocd, int buflen);
+			   unsigned char *eocd, int buflen, int *errp);
 static int _zip_read2(unsigned char **a);
 static int _zip_read4(unsigned char **a);
 static char *_zip_readstr(unsigned char **buf, int len, int nulp);
@@ -86,11 +86,12 @@
     
     if (stat(fn, &st) != 0) {
 	if (flags & ZIP_CREATE) {
-	    cdir = _zip_new();
-	    /* XXX: check cdir != NULL */
+	    if ((cdir=_zip_new(errp)) == NULL)
+		return NULL;
+	    
 	    cdir->zn = strdup(fn);
 	    if (!cdir->zn) {
-		/* XXX: free cdir */
+		_zip_free(cdir);
 		set_error(errp, ZERR_MEMORY);
 		return NULL;
 	    }
@@ -148,7 +149,7 @@
 	/* found match -- check, if good */
 	/* to avoid finding the same match all over again */
 	match++;
-	if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen)) == NULL)
+	if ((cdirnew=_zip_readcdir(fp, buf, match-1, buflen, errp)) == NULL)
 	    continue;	    
 
 	if (cdir) {
@@ -211,11 +212,12 @@
 /* _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 zipfile struct which contains the central directory 
+   Returns a struct zip which contains the central directory 
    entries, or NULL if unsuccessful. */
 
 static struct zip *
-_zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen)
+_zip_readcdir(FILE *fp, unsigned char *buf, unsigned char *eocd, int buflen,
+	      int *errp)
 {
     struct zip *zf;
     unsigned char *cdp;
@@ -225,25 +227,23 @@
     comlen = buf + buflen - eocd - EOCDLEN;
     if (comlen < 0) {
 	/* not enough bytes left for comment */
-	zip_err = ZERR_NOZIP;
+	set_error(errp, ZERR_NOZIP);
 	return NULL;
     }
 
     /* check for end-of-central-dir magic */
     if (memcmp(eocd, EOCD_MAGIC, 4) != 0) {
-	zip_err = ZERR_NOZIP;
+	set_error(errp, ZERR_NOZIP);
 	return NULL;
     }
 
     if (memcmp(eocd+4, "\0\0\0\0", 4) != 0) {
-	zip_err = ZERR_MULTIDISK;
+	set_error(errp, ZERR_MULTIDISK);
 	return NULL;
     }
 
-    if ((zf=_zip_new()) == NULL) {
-	zip_err = ZERR_MEMORY;
+    if ((zf=_zip_new(errp)) == NULL)
 	return NULL;
-    }
 
     cdp = eocd + 8;
     /* number of cdir-entries on this disk */
@@ -261,7 +261,7 @@
 	 (zf->comlen != comlen-2)) || (entries != i)) {
 	/* comment size wrong -- too few or too many left after central dir */
 	/* or number of cdir-entries on this disk != number of cdir-entries */
-	zip_err = ZERR_NOZIP;
+	set_error(errp, ZERR_NOZIP);
 	_zip_free(zf);
 	return NULL;
     }
@@ -282,9 +282,9 @@
 	if (ferror(fp) || (ftell(fp) != zf->cd_offset)) {
 	    /* seek error or offset of cdir wrong */
 	    if (ferror(fp))
-		zip_err = ZERR_SEEK;
+		set_error(errp, ZERR_SEEK);
 	    else
-		zip_err = ZERR_NOZIP;
+		set_error(errp, ZERR_NOZIP);
 	    _zip_free(zf);
 	    return NULL;
 	}
@@ -293,7 +293,8 @@
     zf->entry = (struct zip_entry *)malloc(sizeof(struct zip_entry)
 					   *entries);
     if (!zf->entry) {
-	zip_err = ZERR_MEMORY;
+	set_error(errp, ZERR_MEMORY);
+	_zip_free(zf);
 	return NULL;
     }
 
@@ -302,6 +303,7 @@
     for (i=0; i<entries; i++) {
 	if (_zip_new_entry(zf) == NULL) {
 	    /* shouldn't happen, since space already has been malloc'd */
+	    _zip_error_get(&zf->error, errp, NULL);
 	    _zip_free(zf);
 	    return NULL;
 	}
diff --git a/lib/zipint.h b/lib/zipint.h
index fc1ccfe..8a74463 100644
--- a/lib/zipint.h
+++ b/lib/zipint.h
@@ -2,7 +2,7 @@
 #define _HAD_ZIPINT_H
 
 /*
-  $NiH: zipint.h,v 1.20 2003/10/06 02:50:07 dillo Exp $
+  $NiH: zipint.h,v 1.21 2003/10/06 16:37:42 dillo Exp $
 
   zipint.h -- internal declarations.
   Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner
@@ -128,7 +128,7 @@
 void *_zip_memdup(const void *, int);
 int _zip_merge_meta(struct zip_meta *, struct zip_meta *);
 int _zip_merge_meta_fix(struct zip_meta *, struct zip_meta *);
-struct zip *_zip_new(void);
+struct zip *_zip_new(int *);
 struct zip_entry *_zip_new_entry(struct zip *);
 int _zip_readcdentry(FILE *, struct zip_entry *, unsigned char **, 
 		     int, int, int);