[Zlib-devel] TR: somes fixes on the contrib/minizip library
Gilles Vollant
info at winimage.com
Tue Dec 22 04:46:22 EST 2009
-----Message d'origine-----
De : Gilles Vollant [mailto:info at winimage.com]
Envoyé : mardi 22 décembre 2009 10:45
À : 'Mark Adler'
Objet : somes fixes on the contrib/minizip library
here is somes minor fix and warning for for the minizip library
and pehaps after a grep from
Version 1.01e, February 12th, 2005
to
Version 1.01f, December 22th, 2009
diff -c zlib-1.2.3.4o\contrib\minizip\ioapi.c
zlib-1.2.3.4\contrib\minizip\ioapi.c
*** zlib-1.2.3.4o\contrib\minizip\ioapi.c Tue Jul 12 19:08:40 2005
--- zlib-1.2.3.4\contrib\minizip\ioapi.c Tue Dec 22 10:18:53 2009
***************
*** 141,147 ****
default: return -1;
}
ret = 0;
! fseek((FILE *)stream, offset, fseek_origin);
return ret;
}
--- 141,148 ----
default: return -1;
}
ret = 0;
! if (fseek((FILE *)stream, offset, fseek_origin) != 0)
! ret = -1;
return ret;
}
diff -c zlib-1.2.3.4o\contrib\minizip\miniunz.c
zlib-1.2.3.4\contrib\minizip\miniunz.c
*** zlib-1.2.3.4o\contrib\minizip\miniunz.c Tue Jul 12 19:08:40 2005
--- zlib-1.2.3.4\contrib\minizip\miniunz.c Tue Dec 22 10:04:11 2009
***************
*** 112,117 ****
--- 112,122 ----
return 0;
buffer = (char*)malloc(len+1);
+ if (buffer==NULL)
+ {
+ printf("Error allocating memory\n");
+ return UNZ_INTERNALERROR;
+ }
strcpy(buffer,newdir);
if (buffer[len-1] == '/') {
***************
*** 470,475 ****
--- 475,481 ----
const char *password=NULL;
char filename_try[MAXFILENAME+16] = "";
int i;
+ int ret_value=0;
int opt_do_list=0;
int opt_do_extract=1;
int opt_do_extract_withoutpath=0;
***************
*** 564,570 ****
printf("%s opened\n",filename_try);
if (opt_do_list==1)
! return do_list(uf);
else if (opt_do_extract==1)
{
if (opt_extractdir && chdir(dirname))
--- 570,576 ----
printf("%s opened\n",filename_try);
if (opt_do_list==1)
! ret_value = do_list(uf);
else if (opt_do_extract==1)
{
if (opt_extractdir && chdir(dirname))
***************
*** 574,585 ****
}
if (filename_to_extract == NULL)
! return
do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
else
! return do_extract_onefile(uf,filename_to_extract,
opt_do_extract_withoutpath,opt_overwrite,password);
}
- unzCloseCurrentFile(uf);
! return 0;
}
--- 580,592 ----
}
if (filename_to_extract == NULL)
! ret_value =
do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password);
else
! ret_value = do_extract_onefile(uf,filename_to_extract,
opt_do_extract_withoutpath,opt_overwrite,password);
}
! unzClose(uf);
!
! return ret_value ;
}
Only in zlib-1.2.3.4\contrib\minizip: minizip diff -c
zlib-1.2.3.4o\contrib\minizip\minizip.c
zlib-1.2.3.4\contrib\minizip\minizip.c
*** zlib-1.2.3.4o\contrib\minizip\minizip.c Tue Jul 12 19:08:40 2005
--- zlib-1.2.3.4\contrib\minizip\minizip.c Tue Dec 22 10:38:53 2009
***************
*** 1,8 ****
/*
minizip.c
! Version 1.01e, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
*/
#include <stdio.h>
--- 1,12 ----
/*
minizip.c
! Version 1.01e-jg, February 12th, 2005
Copyright (C) 1998-2005 Gilles Vollant
+
+ Changes:
+ Aug 3, 2006. jg. support storing files with out paths. (-x)
+ Aug 3, 2006. jg. files with paths should not have leading
slashes.
*/
#include <stdio.h>
***************
*** 129,146 ****
void do_banner()
{
! printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles
Vollant\n");
! printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n");
}
void do_help()
{
! printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] file.zip
[files_to_add]\n\n" \
" -o Overwrite existing file.zip\n" \
" -a Append to existing file.zip\n" \
" -0 Store only\n" \
" -1 Compress faster\n" \
! " -9 Compress better\n\n");
}
/* calculate the CRC32 of a file,
--- 133,152 ----
void do_banner()
{
! printf("MiniZip 1.01e-jg, demo of zLib + Zip package written by Gilles
Vollant\n");
! printf("minor updates, jg.\n");
! printf("more info at
http://www.winimage.com/zLibDll/minizip.html\n\n");
}
void do_help()
{
! printf("Usage : minizip [-o] [-a] [-0 to -9] [-p password] [-x]
file.zip [files_to_add]\n\n" \
" -o Overwrite existing file.zip\n" \
" -a Append to existing file.zip\n" \
" -0 Store only\n" \
" -1 Compress faster\n" \
! " -9 Compress better\n" \
! " -x exclude path. store only the file name.\n\n");
}
/* calculate the CRC32 of a file,
***************
*** 179,185 ****
fclose(fin);
*result_crc=calculate_crc;
! printf("file %s crc %x\n",filenameinzip,calculate_crc);
return err;
}
--- 185,191 ----
fclose(fin);
*result_crc=calculate_crc;
! printf("file %s crc %lx\n",filenameinzip,calculate_crc);
return err;
}
***************
*** 190,195 ****
--- 196,202 ----
int i;
int opt_overwrite=0;
int opt_compress_level=Z_DEFAULT_COMPRESSION;
+ int opt_exclude_path=0;
int zipfilenamearg = 0;
char filename_try[MAXFILENAME+16];
int zipok;
***************
*** 222,227 ****
--- 229,236 ----
opt_overwrite = 2;
if ((c>='0') && (c<='9'))
opt_compress_level = c-'0';
+ if ((c=='x') || (c=='X'))
+ opt_exclude_path = 1;
if (((c=='p') || (c=='P')) && (i+1<argc))
{
***************
*** 231,238 ****
--- 240,251 ----
}
}
else
+ {
if (zipfilenamearg == 0)
+ {
zipfilenamearg = i ;
+ }
+ }
}
}
***************
*** 245,251 ****
--- 258,266 ----
}
if (zipfilenamearg==0)
+ {
zipok=0;
+ }
else
{
int i,len;
***************
*** 329,334 ****
--- 344,350 ----
FILE * fin;
int size_read;
const char* filenameinzip = argv[i];
+ const char *savefilenameinzip;
zip_fileinfo zi;
unsigned long crcFile=0;
***************
*** 348,354 ****
if ((password != NULL) && (err==ZIP_OK))
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
! err = zipOpenNewFileInZip3(zf,filenameinzip,&zi,
NULL,0,NULL,0,NULL /* comment*/,
(opt_compress_level != 0) ? Z_DEFLATED :
0,
opt_compress_level,0,
--- 364,397 ----
if ((password != NULL) && (err==ZIP_OK))
err = getFileCrc(filenameinzip,buf,size_buf,&crcFile);
! /*the path name saved, should not include a leading slash.
*/
! /*if it did, windows/xp and dynazip couldn't read the zip
file. */
! savefilenameinzip = filenameinzip;
! while( savefilenameinzip[0] == '\\' ||
savefilenameinzip[0] == '/' )
! {
! savefilenameinzip++;
! }
!
! /*should the zip file contain any path at all?*/
! if( opt_exclude_path )
! {
! const char *tmpptr;
! const char *lastslash = 0;
! for( tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
! {
! if( *tmpptr == '\\' || *tmpptr == '/')
! {
! lastslash = tmpptr;
! }
! }
! if( lastslash != NULL )
! {
! savefilenameinzip = lastslash+1; // base filename
follows last slash.
! }
! }
!
! /**/
! err = zipOpenNewFileInZip3(zf,savefilenameinzip,&zi,
NULL,0,NULL,0,NULL /* comment*/,
(opt_compress_level != 0) ? Z_DEFLATED :
0,
opt_compress_level,0, Only in
zlib-1.2.3.4\contrib\minizip: modifzip.zip Only in
zlib-1.2.3.4\contrib\minizip: new diff -c
zlib-1.2.3.4o\contrib\minizip\unzip.c zlib-1.2.3.4\contrib\minizip\unzip.c
*** zlib-1.2.3.4o\contrib\minizip\unzip.c Sun Aug 20 20:42:38 2006
--- zlib-1.2.3.4\contrib\minizip\unzip.c Tue Dec 22 09:46:34 2009
***************
*** 204,210 ****
uLong *pX;
{
uLong x ;
! int i;
int err;
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
--- 204,210 ----
uLong *pX;
{
uLong x ;
! int i = 0;
int err;
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
***************
*** 232,238 ****
uLong *pX;
{
uLong x ;
! int i;
int err;
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
--- 232,238 ----
uLong *pX;
{
uLong x ;
! int i = 0;
int err;
err = unzlocal_getByte(pzlib_filefunc_def,filestream,&i);
***************
*** 491,498 ****
s=(unz_s*)ALLOC(sizeof(unz_s));
! *s=us;
! unzGoToFirstFile((unzFile)s);
return (unzFile)s;
}
--- 491,501 ----
s=(unz_s*)ALLOC(sizeof(unz_s));
! if (s!=NULL)
! {
! *s=us;
! unzGoToFirstFile((unzFile)s);
! }
return (unzFile)s;
}
***************
*** 608,617 ****
--- 611,622 ----
/* we check the magic */
if (err==UNZ_OK)
+ {
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) !=
UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x02014b50)
err=UNZ_BADZIPFILE;
+ }
if (unzlocal_getShort(&s->z_filefunc,
s->filestream,&file_info.version) != UNZ_OK)
err=UNZ_ERRNO;
***************
*** 688,697 ****
--- 693,705 ----
uSizeRead = extraFieldBufferSize;
if (lSeek!=0)
+ {
if (ZSEEK(s->z_filefunc,
s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
+ }
+
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
if (ZREAD(s->z_filefunc,
s->filestream,extraField,uSizeRead)!=uSizeRead)
err=UNZ_ERRNO;
***************
*** 713,722 ****
--- 721,733 ----
uSizeRead = commentBufferSize;
if (lSeek!=0)
+ {
if (ZSEEK(s->z_filefunc,
s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
+ }
+
if ((file_info.size_file_comment>0) && (commentBufferSize>0))
if (ZREAD(s->z_filefunc,
s->filestream,szComment,uSizeRead)!=uSizeRead)
err=UNZ_ERRNO;
***************
*** 977,986 ****
--- 988,999 ----
if (err==UNZ_OK)
+ {
if (unzlocal_getLong(&s->z_filefunc, s->filestream,&uMagic) !=
UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x04034b50)
err=UNZ_BADZIPFILE;
+ }
if (unzlocal_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK)
err=UNZ_ERRNO;
***************
*** 1536,1542 ****
char *szComment;
uLong uSizeBuf;
{
- int err=UNZ_OK;
unz_s* s;
uLong uReadThis ;
if (file==NULL)
--- 1549,1554 ----
***************
*** 1569,1575 ****
unz_s* s;
if (file==NULL)
! return UNZ_PARAMERROR;
s=(unz_s*)file;
if (!s->current_file_ok)
return 0;
--- 1581,1587 ----
unz_s* s;
if (file==NULL)
! return (uLong)UNZ_PARAMERROR;
s=(unz_s*)file;
if (!s->current_file_ok)
return 0;
diff -c zlib-1.2.3.4o\contrib\minizip\zip.c
zlib-1.2.3.4\contrib\minizip\zip.c
*** zlib-1.2.3.4o\contrib\minizip\zip.c Tue Jul 12 19:08:40 2005
--- zlib-1.2.3.4\contrib\minizip\zip.c Tue Dec 22 10:14:08 2009
***************
*** 320,328 ****
uLong dosDate;
{
uLong year = (uLong)ptm->tm_year;
! if (year>1980)
year-=1980;
! else if (year>80)
year-=80;
return
(uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) <<
16) |
--- 320,328 ----
uLong dosDate;
{
uLong year = (uLong)ptm->tm_year;
! if (year>=1980)
year-=1980;
! else if (year>=80)
year-=80;
return
(uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) <<
16) |
***************
*** 373,379 ****
uLong *pX;
{
uLong x ;
! int i;
int err;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
--- 373,379 ----
uLong *pX;
{
uLong x ;
! int i = 0;
int err;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
***************
*** 401,407 ****
uLong *pX;
{
uLong x ;
! int i;
int err;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
--- 401,407 ----
uLong *pX;
{
uLong x ;
! int i = 0;
int err;
err = ziplocal_getByte(pzlib_filefunc_def,filestream,&i);
***************
*** 432,498 ****
/*
Locate the Central directory of a zipfile (at the end, just before
the global comment)
*/
local uLong ziplocal_SearchCentralDir OF((
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream));
! local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream)
! const zlib_filefunc_def* pzlib_filefunc_def;
! voidpf filestream;
! {
! unsigned char* buf;
! uLong uSizeFile;
! uLong uBackRead;
! uLong uMaxBack=0xffff; /* maximum size of global comment */
! uLong uPosFound=0;
!
! if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) !=
0)
! return 0;
!
!
! uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
!
! if (uMaxBack>uSizeFile)
! uMaxBack = uSizeFile;
!
! buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
! if (buf==NULL)
! return 0;
!
! uBackRead = 4;
! while (uBackRead<uMaxBack)
! {
! uLong uReadSize,uReadPos ;
! int i;
! if (uBackRead+BUFREADCOMMENT>uMaxBack)
! uBackRead = uMaxBack;
! else
! uBackRead+=BUFREADCOMMENT;
! uReadPos = uSizeFile-uBackRead ;
!
! uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
! (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
! if
(ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
! break;
!
! if
(ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
! break;
!
! for (i=(int)uReadSize-3; (i--)>0;)
! if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
! ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
! {
! uPosFound = uReadPos+i;
! break;
! }
!
! if (uPosFound!=0)
! break;
! }
! TRYFREE(buf);
! return uPosFound;
}
#endif /* !NO_ADDFILEINEXISTINGZIP*/
/************************************************************/
--- 432,503 ----
/*
Locate the Central directory of a zipfile (at the end, just before
the global comment)
+ Fix from Riccardo Cohen
*/
local uLong ziplocal_SearchCentralDir OF((
const zlib_filefunc_def* pzlib_filefunc_def,
voidpf filestream));
! local uLong ziplocal_SearchCentralDir(pzlib_filefunc_def,filestream,found)
! const zlib_filefunc_def* pzlib_filefunc_def;
! voidpf filestream;
! unsigned char *found;
! {
! unsigned char* buf;
! uLong uSizeFile;
! uLong uBackRead;
! uLong uMaxBack=0xffff; /* maximum size of global comment */
! uLong uPosFound=0;
! *found=0;
!
! if (ZSEEK(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) !=
0)
! return 0;
!
!
! uSizeFile = ZTELL(*pzlib_filefunc_def,filestream);
!
! if (uMaxBack>uSizeFile)
! uMaxBack = uSizeFile;
!
! buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
! if (buf==NULL)
! return 0;
!
! uBackRead = 4;
! while (uBackRead<uMaxBack)
! {
! uLong uReadSize,uReadPos ;
! int i;
! if (uBackRead+BUFREADCOMMENT>uMaxBack)
! uBackRead = uMaxBack;
! else
! uBackRead+=BUFREADCOMMENT;
! uReadPos = uSizeFile-uBackRead ;
!
! uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
! (BUFREADCOMMENT+4) : (uSizeFile-uReadPos);
! if
(ZSEEK(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
! break;
!
! if
(ZREAD(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
! break;
!
! for (i=(int)uReadSize-3; (i--)>0;)
! if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
! ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
! {
! uPosFound = uReadPos+i;
! *found=1;
! break;
! }
!
! if (uPosFound!=0)
! break;
! }
! TRYFREE(buf);
! return uPosFound;
}
+
#endif /* !NO_ADDFILEINEXISTINGZIP*/
/************************************************************/
***************
*** 521,526 ****
--- 526,533 ----
if (ziinit.filestream == NULL)
return NULL;
+ if (append == APPEND_STATUS_CREATEAFTER)
+ ZSEEK(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
ziinit.begin_pos = ZTELL(ziinit.z_filefunc,ziinit.filestream);
ziinit.in_opened_file_inzip = 0;
ziinit.ci.stream_initialised = 0;
***************
*** 615,621 ****
if (size_comment>0)
{
! ziinit.globalcomment = ALLOC(size_comment+1);
if (ziinit.globalcomment)
{
size_comment = ZREAD(ziinit.z_filefunc,
ziinit.filestream,ziinit.globalcomment,size_comment);
--- 622,628 ----
if (size_comment>0)
{
! ziinit.globalcomment = (char*)ALLOC(size_comment+1);
if (ziinit.globalcomment)
{
size_comment = ZREAD(ziinit.z_filefunc,
ziinit.filestream,ziinit.globalcomment,size_comment);
***************
*** 857,862 ****
--- 864,870 ----
zi->ci.stream.next_out = zi->ci.buffered_data;
zi->ci.stream.total_in = 0;
zi->ci.stream.total_out = 0;
+ zi->ci.stream.data_type = Z_BINARY;
if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
{
***************
*** 978,986 ****
if (zi->in_opened_file_inzip == 0)
return ZIP_PARAMERROR;
! zi->ci.stream.next_in = (void*)buf;
zi->ci.stream.avail_in = len;
! zi->ci.crc32 = crc32(zi->ci.crc32,buf,len);
while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
{
--- 986,994 ----
if (zi->in_opened_file_inzip == 0)
return ZIP_PARAMERROR;
! zi->ci.stream.next_in = (Bytef*)buf;
zi->ci.stream.avail_in = len;
! zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
{
***************
*** 1173,1179 ****
ldi = ldi->next_datablock;
}
}
! free_datablock(zi->central_dir.first_block);
if (err==ZIP_OK) /* Magic End */
err =
ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
--- 1181,1187 ----
ldi = ldi->next_datablock;
}
}
! free_linkedlist(&(zi->central_dir));
if (err==ZIP_OK) /* Magic End */
err =
ziplocal_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
More information about the Zlib-devel
mailing list