Read unzip.h for more info
*/
+/* Modified my Joseph Wenninger*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "zlib.h"
#include "unzip.h"
+#include "toolbox/logging.h"
#ifdef STDC
# include <stddef.h>
#include "global.h"
#include "tables.h"
-#ifndef local
-# define local static
-#endif
-/* compile with -Dlocal if your debugger can't find static symbols */
const char unz_copyright[] =
" unzip 0.15 Copyright 1998 Gilles Vollant ";
-/* unz_file_info_interntal contain internal info about a file in zipfile*/
-typedef struct unz_file_info_internal_s
-{
- uLong offset_curfile;/* relative offset of local header 4 bytes */
-} unz_file_info_internal;
-
-
-/* file_in_zip_read_info_s contain internal information about a file in zipfile,
- when reading and decompress it */
-typedef struct
-{
- char *read_buffer; /* internal buffer for compressed data */
- z_stream stream; /* zLib stream structure for inflate */
-
- uLong pos_in_zipfile; /* position in byte on the zipfile, for fseek*/
- uLong stream_initialised; /* flag set if stream structure is initialised*/
-
- uLong offset_local_extrafield;/* offset of the local extra field */
- uInt size_local_extrafield;/* size of the local extra field */
- uLong pos_local_extrafield; /* position in the local extra field in read*/
-
- uLong crc32; /* crc32 of all data uncompressed */
- uLong crc32_wait; /* crc32 we must obtain after decompress all */
- uLong rest_read_compressed; /* number of byte to be decompressed */
- uLong rest_read_uncompressed;/*number of byte to be obtained after decomp*/
- FILE* file; /* io structore of the zipfile */
- uLong compression_method; /* compression method (0==store) */
- uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
-} file_in_zip_read_info_s;
-
-
-/*JOWENN*/
-typedef struct cacao_entry
-{
- struct cacao_entry *next;
- utf *name;
- uLong pos;
-} cacao_entry_s;
-
-/* unz_s contain internal information about the zipfile
-*/
-typedef struct
-{
- FILE* file; /* io structore of the zipfile */
- unz_global_info gi; /* public global information */
- uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
- uLong num_file; /* number of the current file in the zipfile*/
- uLong pos_in_central_dir; /* pos of the current file in the central dir*/
- uLong current_file_ok; /* flag about the usability of the current file*/
- uLong central_pos; /* position of the beginning of the central dir*/
-
- uLong size_central_dir; /* size of the central directory */
- uLong offset_central_dir; /* offset of start of central directory with
- respect to the starting disk number */
-
- unz_file_info cur_file_info; /* public info about the current file in zip*/
- unz_file_info_internal cur_file_info_internal; /* private info about it*/
- file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current
- file if we are decompressing it */
- cacao_entry_s *cacao_dir_list;
-} unz_s;
-
/* ===========================================================================
Read a byte from a gz_stream; update next_in and avail_in. Return EOF
*/
-local int unzlocal_getByte(fin,pi)
+ int unzlocal_getByte(fin,pi)
FILE *fin;
int *pi;
{
/* ===========================================================================
Reads a long in LSB order from the given gz_stream. Sets
*/
-local int unzlocal_getShort (fin,pX)
+ int unzlocal_getShort (fin,pX)
FILE* fin;
uLong *pX;
{
return err;
}
-local int unzlocal_getLong (fin,pX)
+ int unzlocal_getLong (fin,pX)
FILE* fin;
uLong *pX;
{
/* My own strcmpi / strcasecmp */
-local int strcmpcasenosensitive_internal (fileName1,fileName2)
+ int strcmpcasenosensitive_internal (fileName1,fileName2)
const char* fileName1;
const char* fileName2;
{
(like 1 on Unix, 2 on Windows)
*/
-extern int ZEXPORT unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
+ int unzStringFileNameCompare (fileName1,fileName2,iCaseSensitivity)
const char* fileName1;
const char* fileName2;
int iCaseSensitivity;
Locate the Central directory of a zipfile (at the end, just before
the global comment)
*/
-local uLong unzlocal_SearchCentralDir(fin)
+ uLong unzlocal_SearchCentralDir(fin)
FILE *fin;
{
unsigned char* buf;
Else, the return value is a unzFile Handle, usable with other function
of this unzip package.
*/
-extern unzFile ZEXPORT unzOpen (path)
+ unzFile unzOpen (path)
const char *path;
{
unz_s us;
If there is files inside the .Zip opened with unzipOpenCurrentFile (see later),
these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzClose (file)
+ int unzClose (file)
unzFile file;
{
unz_s* s;
Write info about the ZipFile in the *pglobal_info structure.
No preparation of the structure is needed
return UNZ_OK if there is no problem. */
-extern int ZEXPORT unzGetGlobalInfo (file,pglobal_info)
+ int unzGetGlobalInfo (file,pglobal_info)
unzFile file;
unz_global_info *pglobal_info;
{
/*
Translate date/time from Dos format to tm_unz (readable more easilty)
*/
-local void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
+ void unzlocal_DosDateToTmuDate (ulDosDate, ptm)
uLong ulDosDate;
tm_unz* ptm;
{
/*
Get Info about the current file in the zipfile, with internal only info
*/
-local int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
+ int unzlocal_GetCurrentFileInfoInternal OF((unzFile file,
unz_file_info *pfile_info,
unz_file_info_internal
*pfile_info_internal,
char *szComment,
uLong commentBufferSize));
-local int unzlocal_GetCurrentFileInfoInternal (file,
+ int unzlocal_GetCurrentFileInfoInternal (file,
pfile_info,
pfile_info_internal,
szFileName, fileNameBufferSize,
/* we check the magic */
- if (err==UNZ_OK)
+ if (err==UNZ_OK) {
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x02014b50)
err=UNZ_BADZIPFILE;
+ }
if (unzlocal_getShort(s->file,&file_info.version) != UNZ_OK)
err=UNZ_ERRNO;
else
uSizeRead = extraFieldBufferSize;
- if (lSeek!=0)
+ if (lSeek!=0) {
if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
+ }
+
if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0))
if (fread(extraField,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO;
else
uSizeRead = commentBufferSize;
- if (lSeek!=0)
+ if (lSeek!=0) {
if (fseek(s->file,lSeek,SEEK_CUR)==0)
lSeek=0;
else
err=UNZ_ERRNO;
+ }
+
if ((file_info.size_file_comment>0) && (commentBufferSize>0))
if (fread(szComment,(uInt)uSizeRead,1,s->file)!=1)
err=UNZ_ERRNO;
No preparation of the structure is needed
return UNZ_OK if there is no problem.
*/
-extern int ZEXPORT unzGetCurrentFileInfo (file,
+ int unzGetCurrentFileInfo (file,
pfile_info,
szFileName, fileNameBufferSize,
extraField, extraFieldBufferSize,
Set the current file of the zipfile to the first file.
return UNZ_OK if there is no problem
*/
-extern int ZEXPORT unzGoToFirstFile (file)
+ int unzGoToFirstFile (file)
unzFile file;
{
int err=UNZ_OK;
return UNZ_OK if there is no problem
return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
*/
-extern int ZEXPORT unzGoToNextFile (file)
+ int unzGoToNextFile (file)
unzFile file;
{
unz_s* s;
if (c) *c='\0';
ent->name=utf_new_char(filename);
};
- printf("Archive contains %d files\n",i);
+ /*printf("Archive contains %d files\n",i);*/
}
UNZ_OK if the file is found. It becomes the current file.
UNZ_END_OF_LIST_OF_FILE if the file is not found
*/
-extern int ZEXPORT unzLocateFile (file, szFileName, iCaseSensitivity)
+ int unzLocateFile (file, szFileName, iCaseSensitivity)
unzFile file;
const char *szFileName;
int iCaseSensitivity;
NULL,0,NULL,0,NULL,0);
}
}
-
- return 0;
+ return UNZ_END_OF_LIST_OF_FILE;
+ /*return 0;*/
}
/*
store in *piSizeVar the size of extra info in local header
(filename and size of extra field data)
*/
-local int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
+ int unzlocal_CheckCurrentFileCoherencyHeader (s,piSizeVar,
poffset_local_extrafield,
psize_local_extrafield)
unz_s* s;
return UNZ_ERRNO;
- if (err==UNZ_OK)
+ if (err==UNZ_OK) {
if (unzlocal_getLong(s->file,&uMagic) != UNZ_OK)
err=UNZ_ERRNO;
else if (uMagic!=0x04034b50)
err=UNZ_BADZIPFILE;
+ }
if (unzlocal_getShort(s->file,&uData) != UNZ_OK)
err=UNZ_ERRNO;
Open for reading data the current file in the zipfile.
If there is no error and the file is opened, the return value is UNZ_OK.
*/
-extern int ZEXPORT unzOpenCurrentFile (file)
+ int unzOpenCurrentFile (file)
unzFile file;
{
int err=UNZ_OK;
return <0 with error code if there is an error
(UNZ_ERRNO for IO error, or zLib error for uncompress error)
*/
-extern int ZEXPORT unzReadCurrentFile (file, buf, len)
+ int unzReadCurrentFile (file, buf, len)
unzFile file;
voidp buf;
unsigned len;
/*
Give the current position in uncompressed data
*/
-extern z_off_t ZEXPORT unztell (file)
+ z_off_t unztell (file)
unzFile file;
{
unz_s* s;
/*
return 1 if the end of file was reached, 0 elsewhere
*/
-extern int ZEXPORT unzeof (file)
+ int unzeof (file)
unzFile file;
{
unz_s* s;
the return value is the number of bytes copied in buf, or (if <0)
the error code
*/
-extern int ZEXPORT unzGetLocalExtrafield (file,buf,len)
+ int unzGetLocalExtrafield (file,buf,len)
unzFile file;
voidp buf;
unsigned len;
Close the file in zip opened with unzipOpenCurrentFile
Return UNZ_CRCERROR if all the file was read but the CRC is not good
*/
-extern int ZEXPORT unzCloseCurrentFile (file)
+ int unzCloseCurrentFile (file)
unzFile file;
{
int err=UNZ_OK;
uSizeBuf is the size of the szComment buffer.
return the number of byte copied or an error code <0
*/
-extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf)
+ int unzGetGlobalComment (file, szComment, uSizeBuf)
unzFile file;
char *szComment;
uLong uSizeBuf;