Try to be consistent in calling struct zips za and struct zip_files zf. --HG-- branch : HEAD
diff --git a/TODO b/TODO index 869274f..35145a1 100644 --- a/TODO +++ b/TODO
@@ -10,11 +10,9 @@ * zipcmp.c:142: warning: passing arg 1 of `compare_zip' from incompatible pointer type * zipcmp.c: In function `compare_zip': * zipcmp.c:189: warning: passing arg 3 of `compare_list' from incompatible pointer type -* struct zip *zf -> struct zip *za * what is ZIP_CMD_CLOSE good for; check callers * man page cleanup: zf/za -> archive; "global variable zip_err" * zipint.h should include zip.h? -* struct zip_file *zff -> struct zip *zf * sort zipint.h contents * documentation: zip_error_sys_type zip_file_get_error zip_get_error
diff --git a/lib/zip_delete.c b/lib/zip_delete.c index b526f17..a234ed2 100644 --- a/lib/zip_delete.c +++ b/lib/zip_delete.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_delete.c,v 1.13 2004/04/16 09:40:27 dillo Exp $ + $NiH: zip_delete.c,v 1.14 2004/11/17 21:55:10 wiz Exp $ zip_delete.c -- delete file from zip archive Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -41,17 +41,17 @@ int -zip_delete(struct zip *zf, int idx) +zip_delete(struct zip *za, int idx) { - if (idx < 0 || idx >= zf->nentry) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (idx < 0 || idx >= za->nentry) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - if (zip_unchange(zf, idx) != 0) + if (zip_unchange(za, idx) != 0) return -1; - zf->entry[idx].state = ZIP_ST_DELETED; + za->entry[idx].state = ZIP_ST_DELETED; return 0; }
diff --git a/lib/zip_fclose.c b/lib/zip_fclose.c index 1119192..9c6bbb5 100644 --- a/lib/zip_fclose.c +++ b/lib/zip_fclose.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fclose.c,v 1.10 2004/04/16 09:40:28 dillo Exp $ + $NiH: zip_fclose.c,v 1.11 2004/04/17 19:15:30 dillo Exp $ zip_fclose.c -- close file in zip archive Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -43,30 +43,30 @@ int -zip_fclose(struct zip_file *zff) +zip_fclose(struct zip_file *zf) { int i, ret; - if (zff->zstr) - inflateEnd(zff->zstr); - free(zff->buffer); - free(zff->zstr); + if (zf->zstr) + inflateEnd(zf->zstr); + free(zf->buffer); + free(zf->zstr); - for (i=0; i<zff->zf->nfile; i++) { - if (zff->zf->file[i] == zff) { - zff->zf->file[i] = zff->zf->file[zff->zf->nfile-1]; - zff->zf->nfile--; + for (i=0; i<zf->za->nfile; i++) { + if (zf->za->file[i] == zf) { + zf->za->file[i] = zf->za->file[zf->za->nfile-1]; + zf->za->nfile--; break; } } /* if EOF, compare CRC */ /* XXX: also compare for stored */ - if ((zff->flags & ZIP_ZF_COMP) == 0 && (zff->flags & ZIP_ZF_EOF)) - ret = (zff->crc_orig == zff->crc); + if ((zf->flags & ZIP_ZF_COMP) == 0 && (zf->flags & ZIP_ZF_EOF)) + ret = (zf->crc_orig == zf->crc); else - ret = zff->error.zip_err; + ret = zf->error.zip_err; - free(zff); + free(zf); return ret; }
diff --git a/lib/zip_fopen_index.c b/lib/zip_fopen_index.c index 02374b3..9ff4ffd 100644 --- a/lib/zip_fopen_index.c +++ b/lib/zip_fopen_index.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fopen_index.c,v 1.19 2004/04/19 11:49:13 dillo Exp $ + $NiH: zip_fopen_index.c,v 1.20 2004/11/17 21:55:11 wiz Exp $ zip_fopen_index.c -- open file in zip archive for reading by index Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -42,128 +42,128 @@ #include "zip.h" #include "zipint.h" -static struct zip_file *_zip_file_new(struct zip *zf); +static struct zip_file *_zip_file_new(struct zip *za); struct zip_file * -zip_fopen_index(struct zip *zf, int fileno, int flags) +zip_fopen_index(struct zip *za, int fileno, int flags) { int len, ret; int zfflags; - struct zip_file *zff; + struct zip_file *zf; - if ((fileno < 0) || (fileno >= zf->nentry)) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if ((fileno < 0) || (fileno >= za->nentry)) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return NULL; } if ((flags & ZIP_FL_UNCHANGED) == 0 - && ZIP_ENTRY_DATA_CHANGED(zf->entry+fileno)) { - _zip_error_set(&zf->error, ZIP_ER_CHANGED, 0); + && ZIP_ENTRY_DATA_CHANGED(za->entry+fileno)) { + _zip_error_set(&za->error, ZIP_ER_CHANGED, 0); return NULL; } - if (fileno >= zf->cdir->nentry) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (fileno >= za->cdir->nentry) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return NULL; } if ((flags & ZIP_FL_COMPRESSED) - || (zf->cdir->entry[fileno].comp_method == ZIP_CM_STORE)) + || (za->cdir->entry[fileno].comp_method == ZIP_CM_STORE)) zfflags = ZIP_ZF_COMP; else { - if (zf->cdir->entry[fileno].comp_method != ZIP_CM_DEFLATE) { - _zip_error_set(&zf->error, ZIP_ER_COMPNOTSUPP, 0); + if (za->cdir->entry[fileno].comp_method != ZIP_CM_DEFLATE) { + _zip_error_set(&za->error, ZIP_ER_COMPNOTSUPP, 0); return NULL; } zfflags = 0; } - zff = _zip_file_new(zf); + zf = _zip_file_new(za); - zff->flags = zfflags; - /* zff->name = zf->cdir->entry[fileno].filename; */ - zff->method = zf->cdir->entry[fileno].comp_method; - zff->bytes_left = zf->cdir->entry[fileno].uncomp_size; - zff->cbytes_left = zf->cdir->entry[fileno].comp_size; - zff->crc_orig = zf->cdir->entry[fileno].crc; + zf->flags = zfflags; + /* zf->name = za->cdir->entry[fileno].filename; */ + zf->method = za->cdir->entry[fileno].comp_method; + zf->bytes_left = za->cdir->entry[fileno].uncomp_size; + zf->cbytes_left = za->cdir->entry[fileno].comp_size; + zf->crc_orig = za->cdir->entry[fileno].crc; - if ((zff->fpos=_zip_file_get_offset(zf, fileno)) == 0) { - zip_fclose(zff); + if ((zf->fpos=_zip_file_get_offset(za, fileno)) == 0) { + zip_fclose(zf); return NULL; } - if (zff->flags & ZIP_ZF_COMP) - zff->bytes_left = zff->cbytes_left; + if (zf->flags & ZIP_ZF_COMP) + zf->bytes_left = zf->cbytes_left; else { - if ((zff->buffer=(char *)malloc(BUFSIZE)) == NULL) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); - zip_fclose(zff); + if ((zf->buffer=(char *)malloc(BUFSIZE)) == NULL) { + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + zip_fclose(zf); return NULL; } - len = _zip_file_fillbuf(zff->buffer, BUFSIZE, zff); + len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf); if (len <= 0) { - _zip_error_copy(&zf->error, &zff->error); - zip_fclose(zff); + _zip_error_copy(&za->error, &zf->error); + zip_fclose(zf); return NULL; } - if ((zff->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); - zip_fclose(zff); + if ((zf->zstr = (z_stream *)malloc(sizeof(z_stream))) == NULL) { + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + zip_fclose(zf); return NULL; } - zff->zstr->zalloc = Z_NULL; - zff->zstr->zfree = Z_NULL; - zff->zstr->opaque = NULL; - zff->zstr->next_in = zff->buffer; - zff->zstr->avail_in = len; + zf->zstr->zalloc = Z_NULL; + zf->zstr->zfree = Z_NULL; + zf->zstr->opaque = NULL; + zf->zstr->next_in = zf->buffer; + zf->zstr->avail_in = len; /* negative value to tell zlib that there is no header */ - if ((ret=inflateInit2(zff->zstr, -MAX_WBITS)) != Z_OK) { - _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret); - zip_fclose(zff); + if ((ret=inflateInit2(zf->zstr, -MAX_WBITS)) != Z_OK) { + _zip_error_set(&za->error, ZIP_ER_ZLIB, ret); + zip_fclose(zf); return NULL; } } - return zff; + return zf; } int -_zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zff) +_zip_file_fillbuf(void *buf, size_t buflen, struct zip_file *zf) { int i, j; - if (zff->error.zip_err != ZIP_ER_OK) + if (zf->error.zip_err != ZIP_ER_OK) return -1; - if ((zff->flags & ZIP_ZF_EOF) || zff->cbytes_left <= 0 || buflen <= 0) + if ((zf->flags & ZIP_ZF_EOF) || zf->cbytes_left <= 0 || buflen <= 0) return 0; - if (fseek(zff->zf->zp, zff->fpos, SEEK_SET) < 0) { - _zip_error_set(&zff->error, ZIP_ER_SEEK, errno); + if (fseek(zf->za->zp, zf->fpos, SEEK_SET) < 0) { + _zip_error_set(&zf->error, ZIP_ER_SEEK, errno); return -1; } - if (buflen < zff->cbytes_left) + if (buflen < zf->cbytes_left) i = buflen; else - i = zff->cbytes_left; + i = zf->cbytes_left; - j = fread(buf, 1, i, zff->zf->zp); + j = fread(buf, 1, i, zf->za->zp); if (j == 0) { - _zip_error_set(&zff->error, ZIP_ER_EOF, 0); + _zip_error_set(&zf->error, ZIP_ER_EOF, 0); j = -1; } else if (j < 0) - _zip_error_set(&zff->error, ZIP_ER_READ, errno); + _zip_error_set(&zf->error, ZIP_ER_READ, errno); else { - zff->fpos += j; - zff->cbytes_left -= j; + zf->fpos += j; + zf->cbytes_left -= j; } return j; @@ -172,41 +172,41 @@ static struct zip_file * -_zip_file_new(struct zip *zf) +_zip_file_new(struct zip *za) { - struct zip_file *zff, **file; + struct zip_file *zf, **file; int n; - if ((zff=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); + if ((zf=(struct zip_file *)malloc(sizeof(struct zip_file))) == NULL) { + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return NULL; } - if (zf->nfile >= zf->nfile_alloc-1) { - n = zf->nfile_alloc + 10; - file = (struct zip_file **)realloc(zf->file, + if (za->nfile >= za->nfile_alloc-1) { + n = za->nfile_alloc + 10; + file = (struct zip_file **)realloc(za->file, n*sizeof(struct zip_file *)); if (file == NULL) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); - free(zff); + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); + free(zf); return NULL; } - zf->nfile_alloc = n; - zf->file = file; + za->nfile_alloc = n; + za->file = file; } - zf->file[zf->nfile++] = zff; + za->file[za->nfile++] = zf; - zff->zf = zf; - _zip_error_init(&zff->error); - zff->flags = 0; - zff->crc = crc32(0L, Z_NULL, 0); - zff->crc_orig = 0; - zff->method = -1; - zff->bytes_left = zff->cbytes_left = 0; - zff->fpos = 0; - zff->buffer = NULL; - zff->zstr = NULL; + zf->za = za; + _zip_error_init(&zf->error); + zf->flags = 0; + zf->crc = crc32(0L, Z_NULL, 0); + zf->crc_orig = 0; + zf->method = -1; + zf->bytes_left = zf->cbytes_left = 0; + zf->fpos = 0; + zf->buffer = NULL; + zf->zstr = NULL; - return zff; + return zf; }
diff --git a/lib/zip_fread.c b/lib/zip_fread.c index c02b12e..11ad594 100644 --- a/lib/zip_fread.c +++ b/lib/zip_fread.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_fread.c,v 1.11 2004/04/17 19:15:30 dillo Exp $ + $NiH: zip_fread.c,v 1.12 2004/11/17 21:55:11 wiz Exp $ zip_fread.c -- read from file Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -41,50 +41,50 @@ ssize_t -zip_fread(struct zip_file *zff, void *outbuf, size_t toread) +zip_fread(struct zip_file *zf, void *outbuf, size_t toread) { int len, out_before, ret; - if (!zff) + if (!zf) return -1; - if (zff->error.zip_err != 0) + if (zf->error.zip_err != 0) return -1; - if ((zff->flags & ZIP_ZF_EOF) || (toread == 0)) + if ((zf->flags & ZIP_ZF_EOF) || (toread == 0)) return 0; - if (zff->bytes_left == 0) { - zff->flags |= ZIP_ZF_EOF; - if ((zff->flags & ZIP_ZF_COMP) == 0) { + if (zf->bytes_left == 0) { + zf->flags |= ZIP_ZF_EOF; + if ((zf->flags & ZIP_ZF_COMP) == 0) { /* XXX: compare for stored */ - if (zff->crc != zff->crc_orig) { - _zip_error_set(&zff->error, ZIP_ER_CRC, 0); + if (zf->crc != zf->crc_orig) { + _zip_error_set(&zf->error, ZIP_ER_CRC, 0); return -1; } } return 0; } - if (zff->flags & ZIP_ZF_COMP) { - ret = _zip_file_fillbuf(outbuf, toread, zff); + if (zf->flags & ZIP_ZF_COMP) { + ret = _zip_file_fillbuf(outbuf, toread, zf); if (ret > 0) { #if 0 /* XXX: compute for stored */ - zff->crc = crc32(zff->crc, outbuf, ret); + zf->crc = crc32(zf->crc, outbuf, ret); #endif - zff->bytes_left -= ret; + zf->bytes_left -= ret; } return ret; } - zff->zstr->next_out = outbuf; - zff->zstr->avail_out = toread; - out_before = zff->zstr->total_out; + zf->zstr->next_out = outbuf; + zf->zstr->avail_out = toread; + out_before = zf->zstr->total_out; /* endless loop until something has been accomplished */ for (;;) { - ret = inflate(zff->zstr, Z_SYNC_FLUSH); + ret = inflate(zf->zstr, Z_SYNC_FLUSH); switch (ret) { case Z_OK: @@ -92,25 +92,25 @@ /* all ok */ /* Z_STREAM_END probably won't happen, since we didn't have a header */ - len = zff->zstr->total_out - out_before; - if (len >= zff->bytes_left || len >= toread) { - zff->crc = crc32(zff->crc, outbuf, len); - zff->bytes_left -= len; + len = zf->zstr->total_out - out_before; + if (len >= zf->bytes_left || len >= toread) { + zf->crc = crc32(zf->crc, outbuf, len); + zf->bytes_left -= len; return len; } break; case Z_BUF_ERROR: - if (zff->zstr->avail_in == 0) { - len = _zip_file_fillbuf(zff->buffer, BUFSIZE, zff); + if (zf->zstr->avail_in == 0) { + len = _zip_file_fillbuf(zf->buffer, BUFSIZE, zf); if (len == 0) { - _zip_error_set(&zff->error, ZIP_ER_INCONS, 0); + _zip_error_set(&zf->error, ZIP_ER_INCONS, 0); return -1; } else if (len < 0) return -1; - zff->zstr->next_in = zff->buffer; - zff->zstr->avail_in = len; + zf->zstr->next_in = zf->buffer; + zf->zstr->avail_in = len; continue; } /* fallthrough */ @@ -118,7 +118,7 @@ case Z_DATA_ERROR: case Z_STREAM_ERROR: case Z_MEM_ERROR: - _zip_error_set(&zff->error, ZIP_ER_ZLIB, ret); + _zip_error_set(&zf->error, ZIP_ER_ZLIB, ret); return -1; } }
diff --git a/lib/zip_free.c b/lib/zip_free.c index 88c602c..b6b8ea6 100644 --- a/lib/zip_free.c +++ b/lib/zip_free.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_free.c,v 1.11 2004/11/17 21:55:11 wiz Exp $ + $NiH: zip_free.c,v 1.12 2004/11/18 15:04:04 wiz Exp $ zip_free.c -- free struct zip Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -46,36 +46,36 @@ corresponding file. */ void -_zip_free(struct zip *zf) +_zip_free(struct zip *za) { int i; - if (zf == NULL) + if (za == NULL) return; - if (zf->zn) - free(zf->zn); + if (za->zn) + free(za->zn); - if (zf->zp) - fclose(zf->zp); + if (za->zp) + fclose(za->zp); - _zip_cdir_free(zf->cdir); + _zip_cdir_free(za->cdir); - if (zf->entry) { - for (i=0; i<zf->nentry; i++) { - _zip_free_entry(zf->entry+i); + if (za->entry) { + for (i=0; i<za->nentry; i++) { + _zip_free_entry(za->entry+i); } - free(zf->entry); + free(za->entry); } - for (i=0; i<zf->nfile; i++) { - zf->file[i]->flags = ZIP_ER_ZIPCLOSED; - zf->file[i]->zf = NULL; + for (i=0; i<za->nfile; i++) { + za->file[i]->flags = ZIP_ER_ZIPCLOSED; + za->file[i]->za = NULL; } - free(zf->file); + free(za->file); - free(zf); + free(za); return; }
diff --git a/lib/zip_get_name.c b/lib/zip_get_name.c index ea64ebc..34f5f3a 100644 --- a/lib/zip_get_name.c +++ b/lib/zip_get_name.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_get_name.c,v 1.8 2004/04/16 09:40:29 dillo Exp $ + $NiH: zip_get_name.c,v 1.9 2004/11/17 21:55:11 wiz Exp $ zip_get_name.c -- get filename for a file in zip file Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -41,15 +41,15 @@ const char * -zip_get_name(struct zip *zf, int idx) +zip_get_name(struct zip *za, int idx) { - if (idx < 0 || idx >= zf->nentry) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (idx < 0 || idx >= za->nentry) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return NULL; } - if (zf->entry[idx].ch_filename) - return zf->entry[idx].ch_filename; + if (za->entry[idx].ch_filename) + return za->entry[idx].ch_filename; - return zf->cdir->entry[idx].filename; + return za->cdir->entry[idx].filename; }
diff --git a/lib/zip_new_entry.c b/lib/zip_new_entry.c index 026b277..9fa8fd5 100644 --- a/lib/zip_new_entry.c +++ b/lib/zip_new_entry.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_new_entry.c,v 1.11 2004/11/17 21:55:12 wiz Exp $ + $NiH: zip_new_entry.c,v 1.12 2004/11/18 15:04:05 wiz Exp $ zip_new_entry.c -- create and init struct zip_entry Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -43,28 +43,28 @@ struct zip_entry * -_zip_new_entry(struct zip *zf) +_zip_new_entry(struct zip *za) { struct zip_entry *ze; - if (!zf) { + if (!za) { ze = (struct zip_entry *)malloc(sizeof(struct zip_entry)); if (!ze) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return NULL; } } else { - if (zf->nentry >= zf->nentry_alloc-1) { - zf->nentry_alloc += 16; - zf->entry = (struct zip_entry *)realloc(zf->entry, + if (za->nentry >= za->nentry_alloc-1) { + za->nentry_alloc += 16; + za->entry = (struct zip_entry *)realloc(za->entry, sizeof(struct zip_entry) - * zf->nentry_alloc); - if (!zf->entry) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); + * za->nentry_alloc); + if (!za->entry) { + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return NULL; } } - ze = zf->entry+zf->nentry; + ze = za->entry+za->nentry; } ze->state = ZIP_ST_UNCHANGED; @@ -72,8 +72,8 @@ ze->ch_filename = NULL; ze->source = NULL; - if (zf) - zf->nentry++; + if (za) + za->nentry++; return ze; }
diff --git a/lib/zip_rename.c b/lib/zip_rename.c index 477dd5c..ab6b669 100644 --- a/lib/zip_rename.c +++ b/lib/zip_rename.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_rename.c,v 1.12 2004/04/16 09:40:29 dillo Exp $ + $NiH: zip_rename.c,v 1.13 2004/11/17 21:55:12 wiz Exp $ zip_rename.c -- rename file in zip archive Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -41,18 +41,18 @@ int -zip_rename(struct zip *zf, int idx, const char *name) +zip_rename(struct zip *za, int idx, const char *name) { - if (idx >= zf->nentry || idx < 0) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (idx >= za->nentry || idx < 0) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } /* XXX: move this to _zip_set_name */ - if (zf->entry[idx].state == ZIP_ST_UNCHANGED) - zf->entry[idx].state = ZIP_ST_RENAMED; + if (za->entry[idx].state == ZIP_ST_UNCHANGED) + za->entry[idx].state = ZIP_ST_RENAMED; - _zip_set_name(zf, idx, name); + _zip_set_name(za, idx, name); return 0; }
diff --git a/lib/zip_set_name.c b/lib/zip_set_name.c index f1c5223..ac5f930 100644 --- a/lib/zip_set_name.c +++ b/lib/zip_set_name.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_set_name.c,v 1.12 2004/04/16 09:40:30 dillo Exp $ + $NiH: zip_set_name.c,v 1.13 2004/11/17 21:55:13 wiz Exp $ zip_set_name.c -- rename helper function Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -43,23 +43,23 @@ int -_zip_set_name(struct zip *zf, int idx, const char *name) +_zip_set_name(struct zip *za, int idx, const char *name) { char *s; - if (idx < 0 || idx >= zf->nentry) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (idx < 0 || idx >= za->nentry) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } if (name != NULL) { if ((s=strdup(name)) == NULL) { - _zip_error_set(&zf->error, ZIP_ER_MEMORY, 0); + _zip_error_set(&za->error, ZIP_ER_MEMORY, 0); return -1; } - free(zf->entry[idx].ch_filename); - zf->entry[idx].ch_filename = s; + free(za->entry[idx].ch_filename); + za->entry[idx].ch_filename = s; } return 0;
diff --git a/lib/zip_unchange.c b/lib/zip_unchange.c index 74c4040..412f431 100644 --- a/lib/zip_unchange.c +++ b/lib/zip_unchange.c
@@ -1,5 +1,5 @@ /* - $NiH: zip_unchange.c,v 1.14 2004/11/17 21:55:14 wiz Exp $ + $NiH: zip_unchange.c,v 1.15 2004/11/18 15:04:05 wiz Exp $ zip_unchange.c -- undo changes to file in zip archive Copyright (C) 1999, 2004 Dieter Baron and Thomas Klausner @@ -42,19 +42,19 @@ int -zip_unchange(struct zip *zf, int idx) +zip_unchange(struct zip *za, int idx) { - if (!zf || idx < 0 || idx >= zf->nentry) { - _zip_error_set(&zf->error, ZIP_ER_INVAL, 0); + if (!za || idx < 0 || idx >= za->nentry) { + _zip_error_set(&za->error, ZIP_ER_INVAL, 0); return -1; } - if (zf->entry[idx].ch_filename) { - free(zf->entry[idx].ch_filename); - zf->entry[idx].ch_filename = NULL; + if (za->entry[idx].ch_filename) { + free(za->entry[idx].ch_filename); + za->entry[idx].ch_filename = NULL; } - _zip_unchange_data(zf->entry+idx); + _zip_unchange_data(za->entry+idx); return 0; }
diff --git a/lib/zipint.h b/lib/zipint.h index a849c6f..946334f 100644 --- a/lib/zipint.h +++ b/lib/zipint.h
@@ -3,7 +3,7 @@ #define _HAD_ZIPINT_H /* - $NiH: zipint.h,v 1.28 2004/11/17 21:55:14 wiz Exp $ + $NiH: zipint.h,v 1.29 2004/11/18 15:04:06 wiz Exp $ zipint.h -- internal declarations. Copyright (C) 1999, 2003, 2004 Dieter Baron and Thomas Klausner @@ -89,7 +89,7 @@ /* file in zip archive, part of API */ struct zip_file { - struct zip *zf; /* zip archive containing this file */ + struct zip *za; /* zip archive containing this file */ struct zip_error error; /* error information */ int flags; /* -1: eof, >0: error */
diff --git a/regress/add_invalid.c b/regress/add_invalid.c index c8ff5af..01b2e27 100644 --- a/regress/add_invalid.c +++ b/regress/add_invalid.c
@@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { - struct zip *zf, *destzf; + struct zip *za, *destza; prg = argv[0]; @@ -17,27 +17,27 @@ } seterrinfo(NULL, argv[1]); - if ((zf=zip_open(argv[1], 0))==NULL) { + if ((za=zip_open(argv[1], 0))==NULL) { myerror(ERRZIPSTR, "can't open file: %s", zip_err_str[zip_err]); return 1; } seterrinfo(NULL, argv[2]); - if ((destzf=zip_open(argv[2], ZIP_CREATE))==NULL) { + if ((destza=zip_open(argv[2], ZIP_CREATE))==NULL) { myerror(ERRZIPSTR, "can't open file: %s", zip_err_str[zip_err]); return 1; } - if (zip_add_zip(destzf, NULL, NULL, zf, 1, 0, 0) == -1) + if (zip_add_zip(destza, NULL, NULL, za, 1, 0, 0) == -1) myerror(ERRZIPSTR, "can't add file to zip-file: %s", zip_err_str[zip_err]); - if (zip_close(destzf)!=0) { + if (zip_close(destza)!=0) { myerror(ERRZIPSTR, "can't close file: %s", zip_err_str[zip_err]); return 1; } seterrinfo(NULL, argv[1]); - if (zip_close(zf)!=0) { + if (zip_close(za)!=0) { myerror(ERRZIPSTR, "can't close file %s", zip_err_str[zip_err]); return 1; }
diff --git a/regress/buffadd.c b/regress/buffadd.c index 76a5e30..339845e 100644 --- a/regress/buffadd.c +++ b/regress/buffadd.c
@@ -1,5 +1,5 @@ /* - $NiH: buffadd.c,v 1.5 2004/04/14 14:01:30 dillo Exp $ + $NiH: buffadd.c,v 1.6 2004/11/18 15:04:07 wiz Exp $ buffadd.c -- test cases for adding files from buffer Copyright (C) 1999, 2003 Dieter Baron and Thomas Klausner @@ -49,8 +49,8 @@ int main(int argc, char *argv[]) { - struct zip *z; - struct zip_file *ze; + struct zip *za; + struct zip_file *zf; struct zip_source *zs; int err; @@ -58,43 +58,43 @@ remove(testzip); - if ((z=zip_open(testzip, ZIP_CREATE, &err)) == NULL) { + if ((za=zip_open(testzip, ZIP_CREATE, &err)) == NULL) { zip_error_to_str(buf, sizeof(buf), err, errno); fprintf(stderr,"%s: can't open zipfile %s: %s\n", argv[0], testzip, buf); exit(1); } - if (zip_add(z, testname, - (zs=zip_source_data(z, teststr, strlen(teststr), 0)))==-1) { + if ((zs=zip_source_data(za, teststr, strlen(teststr), 0)) == NULL + || zip_add(za, testname, zs) == -1) { zip_source_free(zs); fprintf(stderr,"%s: can't add buffer '%s': %s\n", argv[0], - teststr, zip_strerror(z)); + teststr, zip_strerror(za)); exit(1); } - if (zip_close(z) == -1) { + if (zip_close(za) == -1) { fprintf(stderr,"%s: can't close zipfile %s\n", argv[0], testzip); exit(1); } - if ((z=zip_open(testzip, ZIP_CHECKCONS, &err))==NULL) { + if ((za=zip_open(testzip, ZIP_CHECKCONS, &err))==NULL) { zip_error_to_str(buf, sizeof(buf), err, errno); fprintf(stderr,"%s: can't re-open zipfile %s: %s\n", argv[0], testzip, buf); exit(1); } - if ((ze=zip_fopen(z, testname, 0))==NULL) { + if ((zf=zip_fopen(za, testname, 0))==NULL) { fprintf(stderr,"%s: can't fopen file '%s' in '%s': %s\n", argv[0], - testname, testzip, zip_strerror(z)); + testname, testzip, zip_strerror(za)); exit(1); } - if (zip_fread(ze, buf, 2000) < 0) { + if (zip_fread(zf, buf, 2000) < 0) { fprintf(stderr,"%s: can't read from '%s' in zipfile '%s': %s\n", - argv[0], testname, testzip, zip_file_strerror(ze)); + argv[0], testname, testzip, zip_file_strerror(zf)); exit(1); } @@ -104,7 +104,7 @@ exit(1); } - if (zip_close(z) == -1) { + if (zip_close(za) == -1) { fprintf(stderr,"%s: can't close zipfile %s\n", argv[0], testzip); exit(1);
diff --git a/regress/deltest.c b/regress/deltest.c index 9262e15..87991e5 100644 --- a/regress/deltest.c +++ b/regress/deltest.c
@@ -7,7 +7,7 @@ int main(int argc, char *argv[]) { - struct zip *z; + struct zip *za; if (argc != 2) { fprintf(stderr, "%s: call with one option: zip-file. First file" @@ -15,19 +15,19 @@ return 1; } - if ((z=zip_open(argv[1], ZIP_CHECKCONS))==NULL) { + if ((za=zip_open(argv[1], ZIP_CHECKCONS))==NULL) { fprintf(stderr, "%s: can't open '%s': %s\n", argv[0], argv[1], zip_err_str[zip_err]); return 1; } - if (zip_delete(z, 0)< 0) { + if (zip_delete(za, 0)< 0) { fprintf(stderr, "%s: can't delete first file in '%s': %s", argv[0], argv[1], zip_err_str[zip_err]); return 1; } - if (zip_close(z)!=0) { + if (zip_close(za)!=0) { fprintf(stderr, "%s: can't close file '%s': %s", argv[0], argv[1], zip_err_str[zip_err]); return 1;
diff --git a/regress/fileadd.c b/regress/fileadd.c index f8d4b3a..3e1cdfe 100644 --- a/regress/fileadd.c +++ b/regress/fileadd.c
@@ -6,7 +6,7 @@ int main(int argc, char *argv[]) { - struct zip *z; + struct zip *za; int i; if (argc < 3) { @@ -15,20 +15,20 @@ exit(1); } - if ((z=zip_open(argv[1], ZIP_CHECKCONS|ZIP_CREATE)) == NULL) { + if ((za=zip_open(argv[1], ZIP_CHECKCONS|ZIP_CREATE)) == NULL) { fprintf(stderr,"%s: can't open zipfile %s: %s\n", argv[0], argv[1], zip_err_str[zip_err]); exit(1); } for (i=0; i<argc-2; i++) - if (zip_add_file(z, NULL, NULL, argv[i+2], 0, -1)==-1) { + if (zip_add_file(za, NULL, NULL, argv[i+2], 0, -1)==-1) { fprintf(stderr,"%s: can't add file %s: %s\n", argv[0], argv[i+2], zip_err_str[zip_err]); exit(1); } - if (zip_close(z) == -1) { + if (zip_close(za) == -1) { fprintf(stderr,"%s: can't close zipfile %s: %s\n", argv[0], argv[1], zip_err_str[zip_err]); exit(1);
diff --git a/regress/ziptest.c b/regress/ziptest.c index a60ab70..7d37be5 100644 --- a/regress/ziptest.c +++ b/regress/ziptest.c
@@ -8,10 +8,10 @@ #if 0 int i; #endif - struct zip *zf, *destzf; + struct zip *za, *destza; #if 0 #define BUFSIZE 65536 - struct zip_file *zff1, *zff2; + struct zip_file *zf1, *zf2; char buf1[BUFSIZE], buf2[BUFSIZE]; #endif @@ -27,69 +27,69 @@ return 1; } - if ((zf=zip_open(argv[1], ZIP_CHECKCONS))==NULL) { + if ((za=zip_open(argv[1], ZIP_CHECKCONS))==NULL) { fprintf(stderr, "%s: %s: can't open file: %s\n", argv[0], argv[1], zip_err_str[zip_err]); return 1; } - if ((destzf=zip_open(argv[2], ZIP_CREATE))==NULL) { + if ((destza=zip_open(argv[2], ZIP_CREATE))==NULL) { fprintf(stderr, "%s: %s: can't open file: %s\n", argv[0], argv[2], zip_err_str[zip_err]); return 1; } #if 0 - for (i=0; i<zf->nentry; i++) { - printf("%8d %s\n", zf->entry[i].uncomp_size, zf->entry[i].fn); - zip_add_zip(destzf, zf->entry[i].fn, zf, i, 0, 0); + for (i=0; i<za->nentry; i++) { + printf("%8d %s\n", za->entry[i].uncomp_size, za->entry[i].fn); + zip_add_zip(destza, za->entry[i].fn, za, i, 0, 0); } #endif - if (zip_add_zip(destzf, NULL, NULL, zf, 0, 0, 0) == -1) + if (zip_add_zip(destza, NULL, NULL, za, 0, 0, 0) == -1) fprintf(stderr, "%s: %s: can't add file to zip '%s': %s\n", argv[0], - zf->entry[0].fn, argv[1], zip_err_str[zip_err]); + za->entry[0].fn, argv[1], zip_err_str[zip_err]); #if 0 - zff1= zff_open_index(zf, 1); - if (!zff1) { + zf1= zf_open_index(za, 1); + if (!zf1) { fprintf(stderr, "boese, boese\n"); exit(100); } - i = zff_read(zff1, buf1, 100); + i = zf_read(zf1, buf1, 100); if (i < 0) - fprintf(stderr, "read error: %s\n", zip_err_str[zff1->flags]); + fprintf(stderr, "read error: %s\n", zip_err_str[zf1->flags]); else { buf1[i] = 0; printf("read %d bytes: '%s'\n", i, buf1); } - zff2 = zff_open_index(zf, 1); - i = zff_read(zff2, buf2, 200); + zf2 = zf_open_index(za, 1); + i = zf_read(zf2, buf2, 200); if (i < 0) - fprintf(stderr, "read error: %s\n", zip_err_str[zff2->flags]); + fprintf(stderr, "read error: %s\n", zip_err_str[zf2->flags]); else { buf2[i] = 0; printf("read %d bytes: '%s'\n", i, buf2); } - i = zff_read(zff1, buf1, 100); + i = zf_read(zf1, buf1, 100); if (i < 0) - fprintf(stderr, "read error: %s\n", zip_err_str[zff1->flags]); + fprintf(stderr, "read error: %s\n", zip_err_str[zf1->flags]); else { buf1[i] = 0; printf("read %d bytes: '%s'\n", i, buf1); } - zff_close(zff1); - zff_close(zff2); + zf_close(zf1); + zf_close(zf2); #endif - if (zip_close(destzf)!=0) { + if (zip_close(destza)!=0) { fprintf(stderr, "%s: %s: can't close file: %s\n", argv[0], argv[2], zip_err_str[zip_err]); return 1; } - if (zip_close(zf)!=0) { + if (zip_close(za)!=0) { fprintf(stderr, "%s: %s: can't close file: %s\n", argv[0], argv[1], zip_err_str[zip_err]); return 1;
diff --git a/src/zipcmp.c b/src/zipcmp.c index 63bf9fe..07706da 100644 --- a/src/zipcmp.c +++ b/src/zipcmp.c
@@ -1,5 +1,5 @@ /* - $NiH: zipcmp.c,v 1.8 2004/04/14 14:01:31 dillo Exp $ + $NiH: zipcmp.c,v 1.9 2004/11/18 15:04:08 wiz Exp $ zipcmp.c -- compare zip files Copyright (C) 2003, 2004 Dieter Baron and Thomas Klausner @@ -86,7 +86,7 @@ int (*cmp)(const void *, const void *), void print(const void *)); static int compare_zip(const char *zn[], int verbose); -static int test_file(struct zip *z, int idx, off_t size, unsigned int crc); +static int test_file(struct zip *za, int idx, off_t size, unsigned int crc); int ignore_case, test_files; @@ -147,7 +147,7 @@ static int compare_zip(const char *zn[], int verbose) { - struct zip *z; + struct zip *za; struct zip_stat st; struct entry *e[2]; int n[2]; @@ -156,14 +156,14 @@ char errstr[1024]; for (i=0; i<2; i++) { - if ((z=zip_open(zn[i], ZIP_CHECKCONS, &err)) == NULL) { + if ((za=zip_open(zn[i], ZIP_CHECKCONS, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); fprintf(stderr, "%s: cannot open zip archive `%s': %s\n", prg, zn[i], errstr); return -1; } - n[i] = zip_get_num_files(z); + n[i] = zip_get_num_files(za); if ((e[i]=malloc(sizeof(*e[i]) * n[i])) == NULL) { fprintf(stderr, "%s: malloc failure\n", prg); @@ -171,15 +171,15 @@ } for (j=0; j<n[i]; j++) { - zip_stat_index(z, j, 0, &st); + zip_stat_index(za, j, 0, &st); e[i][j].name = strdup(st.name); e[i][j].size = st.size; e[i][j].crc = st.crc; if (test_files) - test_file(z, j, st.size, st.crc); + test_file(za, j, st.size, st.crc); } - zip_close(z); + zip_close(za); qsort(e[i], n[i], sizeof(e[i][0]), entry_cmp); } @@ -282,34 +282,34 @@ static int -test_file(struct zip *z, int idx, off_t size, unsigned int crc) +test_file(struct zip *za, int idx, off_t size, unsigned int crc) { - struct zip_file *f; + struct zip_file *zf; char buf[8192]; int n, nsize, ncrc; - if ((f=zip_fopen_index(z, idx, 0)) == NULL) { + if ((zf=zip_fopen_index(za, idx, 0)) == NULL) { fprintf(stderr, "%s: cannot open file %d in archive: %s\n", - prg, idx, zip_strerror(z)); + prg, idx, zip_strerror(za)); return -1; } ncrc = crc32(0, NULL, 0); nsize = 0; - while ((n=zip_fread(f, buf, sizeof(buf))) > 0) { + while ((n=zip_fread(zf, buf, sizeof(buf))) > 0) { nsize += n; ncrc = crc32(ncrc, buf, n); } if (n < 0) { fprintf(stderr, "%s: error reading file %d in archive: %s\n", - prg, idx, zip_file_strerror(f)); - zip_fclose(f); + prg, idx, zip_file_strerror(zf)); + zip_fclose(zf); return -1; } - zip_fclose(f); + zip_fclose(zf); if (nsize != size) { /* XXX: proper printf identifier */
diff --git a/src/zipmerge.c b/src/zipmerge.c index cd78a02..a1ce75b 100644 --- a/src/zipmerge.c +++ b/src/zipmerge.c
@@ -1,5 +1,5 @@ /* - $NiH: zipmerge.c,v 1.2 2004/05/16 00:51:50 dillo Exp $ + $NiH: zipmerge.c,v 1.3 2004/11/18 15:04:08 wiz Exp $ zipmerge.c -- merge zip archives Copyright (C) 2004 Dieter Baron and Thomas Klausner @@ -83,14 +83,14 @@ static int confirm_replace(struct zip *, const char *, int, struct zip *, const char *, int); -static int merge_zip(struct zip *zt, const char *, const char *); +static int merge_zip(struct zip *za, const char *, const char *); int main(int argc, char *argv[]) { - struct zip *zt; + struct zip *za; int c, err; char errstr[1024], *tname; @@ -140,7 +140,7 @@ } tname = argv[optind++]; - if ((zt=zip_open(tname, ZIP_CREATE, &err)) == NULL) { + if ((za=zip_open(tname, ZIP_CREATE, &err)) == NULL) { zip_error_to_str(errstr, sizeof(errstr), err, errno); fprintf(stderr, "%s: cannot open zip archive `%s': %s\n", prg, tname, errstr); @@ -148,13 +148,13 @@ } while (optind<argc) { - if (merge_zip(zt, tname, argv[optind++]) < 0) + if (merge_zip(za, tname, argv[optind++]) < 0) exit(1); } - if (zip_close(zt) < 0) { + if (zip_close(za) < 0) { fprintf(stderr, "%s: cannot write zip archive `%s': %s\n", - prg, tname, zip_strerror(zt)); + prg, tname, zip_strerror(za)); exit(1); } @@ -164,7 +164,7 @@ static int -confirm_replace(struct zip *zt, const char *tname, int it, +confirm_replace(struct zip *za, const char *tname, int it, struct zip *zs, const char *sname, int is) { char line[1024]; @@ -175,9 +175,9 @@ else if (confirm & CONFIRM_ALL_NO) return 0; - if (zip_stat_index(zt, it, ZIP_FL_UNCHANGED, &st) < 0) { + if (zip_stat_index(za, it, ZIP_FL_UNCHANGED, &st) < 0) { fprintf(stderr, "%s: cannot stat file %d in `%s': %s\n", - prg, it, tname, zip_strerror(zt)); + prg, it, tname, zip_strerror(za)); return -1; } if (zip_stat_index(zs, is, 0, &ss) < 0) { @@ -214,7 +214,7 @@ static int -merge_zip(struct zip *zt, const char *tname, const char *sname) +merge_zip(struct zip *za, const char *tname, const char *sname) { struct zip *zs; struct zip_source *source; @@ -232,18 +232,18 @@ for (i=0; i<zip_get_num_files(zs); i++) { fname = zip_get_name(zs, i); - if ((idx=zip_name_locate(zt, fname, name_flags)) != -1) { - switch (confirm_replace(zt, tname, idx, zs, sname, i)) { + if ((idx=zip_name_locate(za, fname, name_flags)) != -1) { + switch (confirm_replace(za, tname, idx, zs, sname, i)) { case 0: break; case 1: - if ((source=zip_source_zip(zt, zs, i, 0, 0, 0)) == NULL - || zip_replace(zt, idx, source) < 0) { + if ((source=zip_source_zip(za, zs, i, 0, 0, 0)) == NULL + || zip_replace(za, idx, source) < 0) { zip_source_free(source); fprintf(stderr, "%s: cannot replace `%s' in `%s': %s\n", - prg, fname, tname, zip_strerror(zt)); + prg, fname, tname, zip_strerror(za)); return -1; } break; @@ -259,12 +259,12 @@ } } else { - if ((source=zip_source_zip(zt, zs, i, 0, 0, 0)) == NULL - || zip_add(zt, fname, source) < 0) { + if ((source=zip_source_zip(za, zs, i, 0, 0, 0)) == NULL + || zip_add(za, fname, source) < 0) { zip_source_free(source); fprintf(stderr, "%s: cannot add `%s' to `%s': %s\n", - prg, fname, tname, zip_strerror(zt)); + prg, fname, tname, zip_strerror(za)); return -1; } }