nuclear@0: /* unzip.c -- IO for uncompress .zip files using zlib nuclear@0: Version 1.1, February 14h, 2010 nuclear@0: part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) nuclear@0: nuclear@0: Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) nuclear@0: nuclear@0: Modifications of Unzip for Zip64 nuclear@0: Copyright (C) 2007-2008 Even Rouault nuclear@0: nuclear@0: Modifications for Zip64 support on both zip and unzip nuclear@0: Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) nuclear@0: nuclear@0: For more info read MiniZip_info.txt nuclear@0: nuclear@0: nuclear@0: ------------------------------------------------------------------------------------ nuclear@0: Decryption code comes from crypt.c by Info-ZIP but has been greatly reduced in terms of nuclear@0: compatibility with older software. The following is from the original crypt.c. nuclear@0: Code woven in by Terry Thorsen 1/2003. nuclear@0: nuclear@0: Copyright (c) 1990-2000 Info-ZIP. All rights reserved. nuclear@0: nuclear@0: See the accompanying file LICENSE, version 2000-Apr-09 or later nuclear@0: (the contents of which are also included in zip.h) for terms of use. nuclear@0: If, for some reason, all these files are missing, the Info-ZIP license nuclear@0: also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html nuclear@0: nuclear@0: crypt.c (full version) by Info-ZIP. Last revised: [see crypt.h] nuclear@0: nuclear@0: The encryption/decryption parts of this source code (as opposed to the nuclear@0: non-echoing password parts) were originally written in Europe. The nuclear@0: whole source package can be freely distributed, including from the USA. nuclear@0: (Prior to January 2000, re-export from the US was a violation of US law.) nuclear@0: nuclear@0: This encryption code is a direct transcription of the algorithm from nuclear@0: Roger Schlafly, described by Phil Katz in the file appnote.txt. This nuclear@0: file (appnote.txt) is distributed with the PKZIP program (even in the nuclear@0: version without encryption capabilities). nuclear@0: nuclear@0: ------------------------------------------------------------------------------------ nuclear@0: nuclear@0: Changes in unzip.c nuclear@0: nuclear@0: 2007-2008 - Even Rouault - Addition of cpl_unzGetCurrentFileZStreamPos nuclear@0: 2007-2008 - Even Rouault - Decoration of symbol names unz* -> cpl_unz* nuclear@0: 2007-2008 - Even Rouault - Remove old C style function prototypes nuclear@0: 2007-2008 - Even Rouault - Add unzip support for ZIP64 nuclear@0: nuclear@0: Copyright (C) 2007-2008 Even Rouault nuclear@0: nuclear@0: nuclear@0: Oct-2009 - Mathias Svensson - Removed cpl_* from symbol names (Even Rouault added them but since this is now moved to a new project (minizip64) I renamed them again). nuclear@0: Oct-2009 - Mathias Svensson - Fixed problem if uncompressed size was > 4G and compressed size was <4G nuclear@0: should only read the compressed/uncompressed size from the Zip64 format if nuclear@0: the size from normal header was 0xFFFFFFFF nuclear@0: Oct-2009 - Mathias Svensson - Applied some bug fixes from paches recived from Gilles Vollant nuclear@0: Oct-2009 - Mathias Svensson - Applied support to unzip files with compression mathod BZIP2 (bzip2 lib is required) nuclear@0: Patch created by Daniel Borca nuclear@0: nuclear@0: Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer nuclear@0: nuclear@0: Copyright (C) 1998 - 2010 Gilles Vollant, Even Rouault, Mathias Svensson nuclear@0: nuclear@0: */ nuclear@0: nuclear@0: nuclear@0: #include nuclear@0: #include nuclear@0: #include nuclear@0: nuclear@0: #ifndef NOUNCRYPT nuclear@0: #define NOUNCRYPT nuclear@0: #endif nuclear@0: nuclear@0: #include "zlib.h" nuclear@0: #include "unzip.h" nuclear@0: nuclear@0: #ifdef STDC nuclear@0: # include nuclear@0: # include nuclear@0: # include nuclear@0: #endif nuclear@0: #ifdef NO_ERRNO_H nuclear@0: extern int errno; nuclear@0: #else nuclear@0: # include nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: #ifndef local nuclear@0: # define local static nuclear@0: #endif nuclear@0: /* compile with -Dlocal if your debugger can't find static symbols */ nuclear@0: nuclear@0: nuclear@0: #ifndef CASESENSITIVITYDEFAULT_NO nuclear@0: # if !defined(unix) && !defined(CASESENSITIVITYDEFAULT_YES) nuclear@0: # define CASESENSITIVITYDEFAULT_NO nuclear@0: # endif nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: #ifndef UNZ_BUFSIZE nuclear@0: #define UNZ_BUFSIZE (16384) nuclear@0: #endif nuclear@0: nuclear@0: #ifndef UNZ_MAXFILENAMEINZIP nuclear@0: #define UNZ_MAXFILENAMEINZIP (256) nuclear@0: #endif nuclear@0: nuclear@0: #ifndef ALLOC nuclear@0: # define ALLOC(size) (malloc(size)) nuclear@0: #endif nuclear@0: #ifndef TRYFREE nuclear@0: # define TRYFREE(p) {if (p) free(p);} nuclear@0: #endif nuclear@0: nuclear@0: #define SIZECENTRALDIRITEM (0x2e) nuclear@0: #define SIZEZIPLOCALHEADER (0x1e) nuclear@0: nuclear@0: nuclear@0: const char unz_copyright[] = nuclear@0: " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; nuclear@0: nuclear@0: /* unz_file_info_interntal contain internal info about a file in zipfile*/ nuclear@0: typedef struct unz_file_info64_internal_s nuclear@0: { nuclear@0: ZPOS64_T offset_curfile;/* relative offset of local header 8 bytes */ nuclear@0: } unz_file_info64_internal; nuclear@0: nuclear@0: nuclear@0: /* file_in_zip_read_info_s contain internal information about a file in zipfile, nuclear@0: when reading and decompress it */ nuclear@0: typedef struct nuclear@0: { nuclear@0: char *read_buffer; /* internal buffer for compressed data */ nuclear@0: z_stream stream; /* zLib stream structure for inflate */ nuclear@0: nuclear@0: #ifdef HAVE_BZIP2 nuclear@0: bz_stream bstream; /* bzLib stream structure for bziped */ nuclear@0: #endif nuclear@0: nuclear@0: ZPOS64_T pos_in_zipfile; /* position in byte on the zipfile, for fseek*/ nuclear@0: uLong stream_initialised; /* flag set if stream structure is initialised*/ nuclear@0: nuclear@0: ZPOS64_T offset_local_extrafield;/* offset of the local extra field */ nuclear@0: uInt size_local_extrafield;/* size of the local extra field */ nuclear@0: ZPOS64_T pos_local_extrafield; /* position in the local extra field in read*/ nuclear@0: ZPOS64_T total_out_64; nuclear@0: nuclear@0: uLong crc32; /* crc32 of all data uncompressed */ nuclear@0: uLong crc32_wait; /* crc32 we must obtain after decompress all */ nuclear@0: ZPOS64_T rest_read_compressed; /* number of byte to be decompressed */ nuclear@0: ZPOS64_T rest_read_uncompressed;/*number of byte to be obtained after decomp*/ nuclear@0: zlib_filefunc64_32_def z_filefunc; nuclear@0: voidpf filestream; /* io structore of the zipfile */ nuclear@0: uLong compression_method; /* compression method (0==store) */ nuclear@0: ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ nuclear@0: int raw; nuclear@0: } file_in_zip64_read_info_s; nuclear@0: nuclear@0: nuclear@0: /* unz64_s contain internal information about the zipfile nuclear@0: */ nuclear@0: typedef struct nuclear@0: { nuclear@0: zlib_filefunc64_32_def z_filefunc; nuclear@0: int is64bitOpenFunction; nuclear@0: voidpf filestream; /* io structore of the zipfile */ nuclear@0: unz_global_info64 gi; /* public global information */ nuclear@0: ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ nuclear@0: ZPOS64_T num_file; /* number of the current file in the zipfile*/ nuclear@0: ZPOS64_T pos_in_central_dir; /* pos of the current file in the central dir*/ nuclear@0: ZPOS64_T current_file_ok; /* flag about the usability of the current file*/ nuclear@0: ZPOS64_T central_pos; /* position of the beginning of the central dir*/ nuclear@0: nuclear@0: ZPOS64_T size_central_dir; /* size of the central directory */ nuclear@0: ZPOS64_T offset_central_dir; /* offset of start of central directory with nuclear@0: respect to the starting disk number */ nuclear@0: nuclear@0: unz_file_info64 cur_file_info; /* public info about the current file in zip*/ nuclear@0: unz_file_info64_internal cur_file_info_internal; /* private info about it*/ nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read; /* structure about the current nuclear@0: file if we are decompressing it */ nuclear@0: int encrypted; nuclear@0: nuclear@0: int isZip64; nuclear@0: nuclear@0: # ifndef NOUNCRYPT nuclear@0: unsigned long keys[3]; /* keys defining the pseudo-random sequence */ nuclear@0: const unsigned long* pcrc_32_tab; nuclear@0: # endif nuclear@0: } unz64_s; nuclear@0: nuclear@0: nuclear@0: #ifndef NOUNCRYPT nuclear@0: #include "crypt.h" nuclear@0: #endif nuclear@0: nuclear@0: /* =========================================================================== nuclear@0: Read a byte from a gz_stream; update next_in and avail_in. Return EOF nuclear@0: for end of file. nuclear@0: IN assertion: the stream s has been sucessfully opened for reading. nuclear@0: */ nuclear@0: nuclear@0: nuclear@0: local int unz64local_getByte OF(( nuclear@0: const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: int *pi)); nuclear@0: nuclear@0: local int unz64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi) nuclear@0: { nuclear@0: unsigned char c; nuclear@0: int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1); nuclear@0: if (err==1) nuclear@0: { nuclear@0: *pi = (int)c; nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: if (ZERROR64(*pzlib_filefunc_def,filestream)) nuclear@0: return UNZ_ERRNO; nuclear@0: else nuclear@0: return UNZ_EOF; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* =========================================================================== nuclear@0: Reads a long in LSB order from the given gz_stream. Sets nuclear@0: */ nuclear@0: local int unz64local_getShort OF(( nuclear@0: const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: uLong *pX)); nuclear@0: nuclear@0: local int unz64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: uLong *pX) nuclear@0: { nuclear@0: uLong x ; nuclear@0: int i = 0; nuclear@0: int err; nuclear@0: nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x = (uLong)i; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((uLong)i)<<8; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: *pX = x; nuclear@0: else nuclear@0: *pX = 0; nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: local int unz64local_getLong OF(( nuclear@0: const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: uLong *pX)); nuclear@0: nuclear@0: local int unz64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: uLong *pX) nuclear@0: { nuclear@0: uLong x ; nuclear@0: int i = 0; nuclear@0: int err; nuclear@0: nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x = (uLong)i; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((uLong)i)<<8; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((uLong)i)<<16; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x += ((uLong)i)<<24; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: *pX = x; nuclear@0: else nuclear@0: *pX = 0; nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: local int unz64local_getLong64 OF(( nuclear@0: const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: ZPOS64_T *pX)); nuclear@0: nuclear@0: nuclear@0: local int unz64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream, nuclear@0: ZPOS64_T *pX) nuclear@0: { nuclear@0: ZPOS64_T x ; nuclear@0: int i = 0; nuclear@0: int err; nuclear@0: nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x = (ZPOS64_T)i; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<8; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<16; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<24; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<32; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<40; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<48; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: err = unz64local_getByte(pzlib_filefunc_def,filestream,&i); nuclear@0: x |= ((ZPOS64_T)i)<<56; nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: *pX = x; nuclear@0: else nuclear@0: *pX = 0; nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: /* My own strcmpi / strcasecmp */ nuclear@0: local int strcmpcasenosensitive_internal (const char* fileName1, const char* fileName2) nuclear@0: { nuclear@0: for (;;) nuclear@0: { nuclear@0: char c1=*(fileName1++); nuclear@0: char c2=*(fileName2++); nuclear@0: if ((c1>='a') && (c1<='z')) nuclear@0: c1 -= 0x20; nuclear@0: if ((c2>='a') && (c2<='z')) nuclear@0: c2 -= 0x20; nuclear@0: if (c1=='\0') nuclear@0: return ((c2=='\0') ? 0 : -1); nuclear@0: if (c2=='\0') nuclear@0: return 1; nuclear@0: if (c1c2) nuclear@0: return 1; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: nuclear@0: #ifdef CASESENSITIVITYDEFAULT_NO nuclear@0: #define CASESENSITIVITYDEFAULTVALUE 2 nuclear@0: #else nuclear@0: #define CASESENSITIVITYDEFAULTVALUE 1 nuclear@0: #endif nuclear@0: nuclear@0: #ifndef STRCMPCASENOSENTIVEFUNCTION nuclear@0: #define STRCMPCASENOSENTIVEFUNCTION strcmpcasenosensitive_internal nuclear@0: #endif nuclear@0: nuclear@0: /* nuclear@0: Compare two filename (fileName1,fileName2). nuclear@0: If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp) nuclear@0: If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi nuclear@0: or strcasecmp) nuclear@0: If iCaseSenisivity = 0, case sensitivity is defaut of your operating system nuclear@0: (like 1 on Unix, 2 on Windows) nuclear@0: nuclear@0: */ nuclear@0: extern int ZEXPORT unzStringFileNameCompare (const char* fileName1, nuclear@0: const char* fileName2, nuclear@0: int iCaseSensitivity) nuclear@0: nuclear@0: { nuclear@0: if (iCaseSensitivity==0) nuclear@0: iCaseSensitivity=CASESENSITIVITYDEFAULTVALUE; nuclear@0: nuclear@0: if (iCaseSensitivity==1) nuclear@0: return strcmp(fileName1,fileName2); nuclear@0: nuclear@0: return STRCMPCASENOSENTIVEFUNCTION(fileName1,fileName2); nuclear@0: } nuclear@0: nuclear@0: #ifndef BUFREADCOMMENT nuclear@0: #define BUFREADCOMMENT (0x400) nuclear@0: #endif nuclear@0: nuclear@0: /* nuclear@0: Locate the Central directory of a zipfile (at the end, just before nuclear@0: the global comment) nuclear@0: */ nuclear@0: local ZPOS64_T unz64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)); nuclear@0: local ZPOS64_T unz64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream) nuclear@0: { nuclear@0: unsigned char* buf; nuclear@0: ZPOS64_T uSizeFile; nuclear@0: ZPOS64_T uBackRead; nuclear@0: ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ nuclear@0: ZPOS64_T uPosFound=0; nuclear@0: nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) nuclear@0: return 0; nuclear@0: nuclear@0: nuclear@0: uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); nuclear@0: nuclear@0: if (uMaxBack>uSizeFile) nuclear@0: uMaxBack = uSizeFile; nuclear@0: nuclear@0: buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); nuclear@0: if (buf==NULL) nuclear@0: return 0; nuclear@0: nuclear@0: uBackRead = 4; nuclear@0: while (uBackReaduMaxBack) nuclear@0: uBackRead = uMaxBack; nuclear@0: else nuclear@0: uBackRead+=BUFREADCOMMENT; nuclear@0: uReadPos = uSizeFile-uBackRead ; nuclear@0: nuclear@0: uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? nuclear@0: (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: break; nuclear@0: nuclear@0: if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) nuclear@0: break; nuclear@0: nuclear@0: for (i=(int)uReadSize-3; (i--)>0;) nuclear@0: if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && nuclear@0: ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06)) nuclear@0: { nuclear@0: uPosFound = uReadPos+i; nuclear@0: break; nuclear@0: } nuclear@0: nuclear@0: if (uPosFound!=0) nuclear@0: break; nuclear@0: } nuclear@0: TRYFREE(buf); nuclear@0: return uPosFound; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Locate the Central directory 64 of a zipfile (at the end, just before nuclear@0: the global comment) nuclear@0: */ nuclear@0: local ZPOS64_T unz64local_SearchCentralDir64 OF(( nuclear@0: const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream)); nuclear@0: nuclear@0: local ZPOS64_T unz64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, nuclear@0: voidpf filestream) nuclear@0: { nuclear@0: unsigned char* buf; nuclear@0: ZPOS64_T uSizeFile; nuclear@0: ZPOS64_T uBackRead; nuclear@0: ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */ nuclear@0: ZPOS64_T uPosFound=0; nuclear@0: uLong uL; nuclear@0: ZPOS64_T relativeOffset; nuclear@0: nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0) nuclear@0: return 0; nuclear@0: nuclear@0: nuclear@0: uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream); nuclear@0: nuclear@0: if (uMaxBack>uSizeFile) nuclear@0: uMaxBack = uSizeFile; nuclear@0: nuclear@0: buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4); nuclear@0: if (buf==NULL) nuclear@0: return 0; nuclear@0: nuclear@0: uBackRead = 4; nuclear@0: while (uBackReaduMaxBack) nuclear@0: uBackRead = uMaxBack; nuclear@0: else nuclear@0: uBackRead+=BUFREADCOMMENT; nuclear@0: uReadPos = uSizeFile-uBackRead ; nuclear@0: nuclear@0: uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ? nuclear@0: (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos); nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: break; nuclear@0: nuclear@0: if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize) nuclear@0: break; nuclear@0: nuclear@0: for (i=(int)uReadSize-3; (i--)>0;) nuclear@0: if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && nuclear@0: ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07)) nuclear@0: { nuclear@0: uPosFound = uReadPos+i; nuclear@0: break; nuclear@0: } nuclear@0: nuclear@0: if (uPosFound!=0) nuclear@0: break; nuclear@0: } nuclear@0: TRYFREE(buf); nuclear@0: if (uPosFound == 0) nuclear@0: return 0; nuclear@0: nuclear@0: /* Zip64 end of central directory locator */ nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return 0; nuclear@0: nuclear@0: /* the signature, already checked */ nuclear@0: if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) nuclear@0: return 0; nuclear@0: nuclear@0: /* number of the disk with the start of the zip64 end of central directory */ nuclear@0: if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) nuclear@0: return 0; nuclear@0: if (uL != 0) nuclear@0: return 0; nuclear@0: nuclear@0: /* relative offset of the zip64 end of central directory record */ nuclear@0: if (unz64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=UNZ_OK) nuclear@0: return 0; nuclear@0: nuclear@0: /* total number of disks */ nuclear@0: if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) nuclear@0: return 0; nuclear@0: if (uL != 1) nuclear@0: return 0; nuclear@0: nuclear@0: /* Goto end of central directory record */ nuclear@0: if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return 0; nuclear@0: nuclear@0: /* the signature */ nuclear@0: if (unz64local_getLong(pzlib_filefunc_def,filestream,&uL)!=UNZ_OK) nuclear@0: return 0; nuclear@0: nuclear@0: if (uL != 0x06064b50) nuclear@0: return 0; nuclear@0: nuclear@0: return relativeOffset; nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: Open a Zip file. path contain the full pathname (by example, nuclear@0: on a Windows NT computer "c:\\test\\zlib114.zip" or on an Unix computer nuclear@0: "zlib/zlib114.zip". nuclear@0: If the zipfile cannot be opened (file doesn't exist or in not valid), the nuclear@0: return value is NULL. nuclear@0: Else, the return value is a unzFile Handle, usable with other function nuclear@0: of this unzip package. nuclear@0: */ nuclear@0: local unzFile unzOpenInternal (const void *path, nuclear@0: zlib_filefunc64_32_def* pzlib_filefunc64_32_def, nuclear@0: int is64bitOpenFunction) nuclear@0: { nuclear@0: unz64_s us; nuclear@0: unz64_s *s; nuclear@0: ZPOS64_T central_pos; nuclear@0: uLong uL; nuclear@0: nuclear@0: uLong number_disk; /* number of the current dist, used for nuclear@0: spaning ZIP, unsupported, always 0*/ nuclear@0: uLong number_disk_with_CD; /* number the the disk with central dir, used nuclear@0: for spaning ZIP, unsupported, always 0*/ nuclear@0: ZPOS64_T number_entry_CD; /* total number of entries in nuclear@0: the central dir nuclear@0: (same than number_entry on nospan) */ nuclear@0: nuclear@0: int err=UNZ_OK; nuclear@0: nuclear@0: if (unz_copyright[0]!=' ') nuclear@0: return NULL; nuclear@0: nuclear@0: us.z_filefunc.zseek32_file = NULL; nuclear@0: us.z_filefunc.ztell32_file = NULL; nuclear@0: if (pzlib_filefunc64_32_def==NULL) nuclear@0: fill_fopen64_filefunc(&us.z_filefunc.zfile_func64); nuclear@0: else nuclear@0: us.z_filefunc = *pzlib_filefunc64_32_def; nuclear@0: us.is64bitOpenFunction = is64bitOpenFunction; nuclear@0: nuclear@0: nuclear@0: nuclear@0: us.filestream = ZOPEN64(us.z_filefunc, nuclear@0: path, nuclear@0: ZLIB_FILEFUNC_MODE_READ | nuclear@0: ZLIB_FILEFUNC_MODE_EXISTING); nuclear@0: if (us.filestream==NULL) nuclear@0: return NULL; nuclear@0: nuclear@0: central_pos = unz64local_SearchCentralDir64(&us.z_filefunc,us.filestream); nuclear@0: if (central_pos) nuclear@0: { nuclear@0: uLong uS; nuclear@0: ZPOS64_T uL64; nuclear@0: nuclear@0: us.isZip64 = 1; nuclear@0: nuclear@0: if (ZSEEK64(us.z_filefunc, us.filestream, nuclear@0: central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* the signature, already checked */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* size of zip64 end of central directory record */ nuclear@0: if (unz64local_getLong64(&us.z_filefunc, us.filestream,&uL64)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* version made by */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* version needed to extract */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&uS)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* number of this disk */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* number of the disk with the start of the central directory */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* total number of entries in the central directory on this disk */ nuclear@0: if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.gi.number_entry)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* total number of entries in the central directory */ nuclear@0: if (unz64local_getLong64(&us.z_filefunc, us.filestream,&number_entry_CD)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if ((number_entry_CD!=us.gi.number_entry) || nuclear@0: (number_disk_with_CD!=0) || nuclear@0: (number_disk!=0)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: /* size of the central directory */ nuclear@0: if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.size_central_dir)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* offset of start of central directory with respect to the nuclear@0: starting disk number */ nuclear@0: if (unz64local_getLong64(&us.z_filefunc, us.filestream,&us.offset_central_dir)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: us.gi.size_comment = 0; nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: central_pos = unz64local_SearchCentralDir(&us.z_filefunc,us.filestream); nuclear@0: if (central_pos==0) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: us.isZip64 = 0; nuclear@0: nuclear@0: if (ZSEEK64(us.z_filefunc, us.filestream, nuclear@0: central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* the signature, already checked */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* number of this disk */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* number of the disk with the start of the central directory */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&number_disk_with_CD)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* total number of entries in the central dir on this disk */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: us.gi.number_entry = uL; nuclear@0: nuclear@0: /* total number of entries in the central dir */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: number_entry_CD = uL; nuclear@0: nuclear@0: if ((number_entry_CD!=us.gi.number_entry) || nuclear@0: (number_disk_with_CD!=0) || nuclear@0: (number_disk!=0)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: /* size of the central directory */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: us.size_central_dir = uL; nuclear@0: nuclear@0: /* offset of start of central directory with respect to the nuclear@0: starting disk number */ nuclear@0: if (unz64local_getLong(&us.z_filefunc, us.filestream,&uL)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: us.offset_central_dir = uL; nuclear@0: nuclear@0: /* zipfile comment length */ nuclear@0: if (unz64local_getShort(&us.z_filefunc, us.filestream,&us.gi.size_comment)!=UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if ((central_pospfile_in_zip_read!=NULL) nuclear@0: unzCloseCurrentFile(file); nuclear@0: nuclear@0: ZCLOSE64(s->z_filefunc, s->filestream); nuclear@0: TRYFREE(s); nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Write info about the ZipFile in the *pglobal_info structure. nuclear@0: No preparation of the structure is needed nuclear@0: return UNZ_OK if there is no problem. */ nuclear@0: extern int ZEXPORT unzGetGlobalInfo64 (unzFile file, unz_global_info64* pglobal_info) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: *pglobal_info=s->gi; nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzGetGlobalInfo (unzFile file, unz_global_info* pglobal_info32) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: /* to do : check if number_entry is not truncated */ nuclear@0: pglobal_info32->number_entry = (uLong)s->gi.number_entry; nuclear@0: pglobal_info32->size_comment = s->gi.size_comment; nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: /* nuclear@0: Translate date/time from Dos format to tm_unz (readable more easilty) nuclear@0: */ nuclear@0: local void unz64local_DosDateToTmuDate (ZPOS64_T ulDosDate, tm_unz* ptm) nuclear@0: { nuclear@0: ZPOS64_T uDate; nuclear@0: uDate = (ZPOS64_T)(ulDosDate>>16); nuclear@0: ptm->tm_mday = (uInt)(uDate&0x1f) ; nuclear@0: ptm->tm_mon = (uInt)((((uDate)&0x1E0)/0x20)-1) ; nuclear@0: ptm->tm_year = (uInt)(((uDate&0x0FE00)/0x0200)+1980) ; nuclear@0: nuclear@0: ptm->tm_hour = (uInt) ((ulDosDate &0xF800)/0x800); nuclear@0: ptm->tm_min = (uInt) ((ulDosDate&0x7E0)/0x20) ; nuclear@0: ptm->tm_sec = (uInt) (2*(ulDosDate&0x1f)) ; nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: Get Info about the current file in the zipfile, with internal only info nuclear@0: */ nuclear@0: local int unz64local_GetCurrentFileInfoInternal OF((unzFile file, nuclear@0: unz_file_info64 *pfile_info, nuclear@0: unz_file_info64_internal nuclear@0: *pfile_info_internal, nuclear@0: char *szFileName, nuclear@0: uLong fileNameBufferSize, nuclear@0: void *extraField, nuclear@0: uLong extraFieldBufferSize, nuclear@0: char *szComment, nuclear@0: uLong commentBufferSize)); nuclear@0: nuclear@0: local int unz64local_GetCurrentFileInfoInternal (unzFile file, nuclear@0: unz_file_info64 *pfile_info, nuclear@0: unz_file_info64_internal nuclear@0: *pfile_info_internal, nuclear@0: char *szFileName, nuclear@0: uLong fileNameBufferSize, nuclear@0: void *extraField, nuclear@0: uLong extraFieldBufferSize, nuclear@0: char *szComment, nuclear@0: uLong commentBufferSize) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: unz_file_info64 file_info; nuclear@0: unz_file_info64_internal file_info_internal; nuclear@0: int err=UNZ_OK; nuclear@0: uLong uMagic; nuclear@0: long lSeek=0; nuclear@0: uLong uL; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: if (ZSEEK64(s->z_filefunc, s->filestream, nuclear@0: s->pos_in_central_dir+s->byte_before_the_zipfile, nuclear@0: ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: nuclear@0: /* we check the magic */ nuclear@0: if (err==UNZ_OK) nuclear@0: { nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: else if (uMagic!=0x02014b50) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: } nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.version_needed) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.flag) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.compression_method) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.dosDate) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: unz64local_DosDateToTmuDate(file_info.dosDate,&file_info.tmu_date); nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.crc) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: file_info.compressed_size = uL; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: file_info.uncompressed_size = uL; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_filename) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_extra) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.size_file_comment) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.disk_num_start) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&file_info.internal_fa) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&file_info.external_fa) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: // relative offset of local header nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: file_info_internal.offset_curfile = uL; nuclear@0: nuclear@0: lSeek+=file_info.size_filename; nuclear@0: if ((err==UNZ_OK) && (szFileName!=NULL)) nuclear@0: { nuclear@0: uLong uSizeRead ; nuclear@0: if (file_info.size_filename0) && (fileNameBufferSize>0)) nuclear@0: if (ZREAD64(s->z_filefunc, s->filestream,szFileName,uSizeRead)!=uSizeRead) nuclear@0: err=UNZ_ERRNO; nuclear@0: lSeek -= uSizeRead; nuclear@0: } nuclear@0: nuclear@0: // Read extrafield nuclear@0: if ((err==UNZ_OK) && (extraField!=NULL)) nuclear@0: { nuclear@0: ZPOS64_T uSizeRead ; nuclear@0: if (file_info.size_file_extraz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) nuclear@0: lSeek=0; nuclear@0: else nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if ((file_info.size_file_extra>0) && (extraFieldBufferSize>0)) nuclear@0: if (ZREAD64(s->z_filefunc, s->filestream,extraField,(uLong)uSizeRead)!=uSizeRead) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: lSeek += file_info.size_file_extra - (uLong)uSizeRead; nuclear@0: } nuclear@0: else nuclear@0: lSeek += file_info.size_file_extra; nuclear@0: nuclear@0: nuclear@0: if ((err==UNZ_OK) && (file_info.size_file_extra != 0)) nuclear@0: { nuclear@0: uLong acc = 0; nuclear@0: nuclear@0: // since lSeek now points to after the extra field we need to move back nuclear@0: lSeek -= file_info.size_file_extra; nuclear@0: nuclear@0: if (lSeek!=0) nuclear@0: { nuclear@0: if (ZSEEK64(s->z_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) nuclear@0: lSeek=0; nuclear@0: else nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: while(acc < file_info.size_file_extra) nuclear@0: { nuclear@0: uLong headerId; nuclear@0: uLong dataSize; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&headerId) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&dataSize) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: /* ZIP64 extra fields */ nuclear@0: if (headerId == 0x0001) nuclear@0: { nuclear@0: uLong uL; nuclear@0: nuclear@0: if(file_info.uncompressed_size == MAXU32) nuclear@0: { nuclear@0: if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.uncompressed_size) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if(file_info.compressed_size == MAXU32) nuclear@0: { nuclear@0: if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info.compressed_size) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if(file_info_internal.offset_curfile == MAXU32) nuclear@0: { nuclear@0: /* Relative Header offset */ nuclear@0: if (unz64local_getLong64(&s->z_filefunc, s->filestream,&file_info_internal.offset_curfile) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if(file_info.disk_num_start == MAXU32) nuclear@0: { nuclear@0: /* Disk Start Number */ nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uL) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: } nuclear@0: else nuclear@0: { nuclear@0: if (ZSEEK64(s->z_filefunc, s->filestream,dataSize,ZLIB_FILEFUNC_SEEK_CUR)!=0) nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: acc += 2 + 2 + dataSize; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: if ((err==UNZ_OK) && (szComment!=NULL)) nuclear@0: { nuclear@0: uLong uSizeRead ; nuclear@0: if (file_info.size_file_commentz_filefunc, s->filestream,lSeek,ZLIB_FILEFUNC_SEEK_CUR)==0) nuclear@0: lSeek=0; nuclear@0: else nuclear@0: err=UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if ((file_info.size_file_comment>0) && (commentBufferSize>0)) nuclear@0: if (ZREAD64(s->z_filefunc, s->filestream,szComment,uSizeRead)!=uSizeRead) nuclear@0: err=UNZ_ERRNO; nuclear@0: lSeek+=file_info.size_file_comment - uSizeRead; nuclear@0: } nuclear@0: else nuclear@0: lSeek+=file_info.size_file_comment; nuclear@0: nuclear@0: nuclear@0: if ((err==UNZ_OK) && (pfile_info!=NULL)) nuclear@0: *pfile_info=file_info; nuclear@0: nuclear@0: if ((err==UNZ_OK) && (pfile_info_internal!=NULL)) nuclear@0: *pfile_info_internal=file_info_internal; nuclear@0: nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Write info about the ZipFile in the *pglobal_info structure. nuclear@0: No preparation of the structure is needed nuclear@0: return UNZ_OK if there is no problem. nuclear@0: */ nuclear@0: extern int ZEXPORT unzGetCurrentFileInfo64 (unzFile file, nuclear@0: unz_file_info64 * pfile_info, nuclear@0: char * szFileName, uLong fileNameBufferSize, nuclear@0: void *extraField, uLong extraFieldBufferSize, nuclear@0: char* szComment, uLong commentBufferSize) nuclear@0: { nuclear@0: return unz64local_GetCurrentFileInfoInternal(file,pfile_info,NULL, nuclear@0: szFileName,fileNameBufferSize, nuclear@0: extraField,extraFieldBufferSize, nuclear@0: szComment,commentBufferSize); nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzGetCurrentFileInfo (unzFile file, nuclear@0: unz_file_info * pfile_info, nuclear@0: char * szFileName, uLong fileNameBufferSize, nuclear@0: void *extraField, uLong extraFieldBufferSize, nuclear@0: char* szComment, uLong commentBufferSize) nuclear@0: { nuclear@0: int err; nuclear@0: unz_file_info64 file_info64; nuclear@0: err = unz64local_GetCurrentFileInfoInternal(file,&file_info64,NULL, nuclear@0: szFileName,fileNameBufferSize, nuclear@0: extraField,extraFieldBufferSize, nuclear@0: szComment,commentBufferSize); nuclear@0: if ((err==UNZ_OK) && (pfile_info != NULL)) nuclear@0: { nuclear@0: pfile_info->version = file_info64.version; nuclear@0: pfile_info->version_needed = file_info64.version_needed; nuclear@0: pfile_info->flag = file_info64.flag; nuclear@0: pfile_info->compression_method = file_info64.compression_method; nuclear@0: pfile_info->dosDate = file_info64.dosDate; nuclear@0: pfile_info->crc = file_info64.crc; nuclear@0: nuclear@0: pfile_info->size_filename = file_info64.size_filename; nuclear@0: pfile_info->size_file_extra = file_info64.size_file_extra; nuclear@0: pfile_info->size_file_comment = file_info64.size_file_comment; nuclear@0: nuclear@0: pfile_info->disk_num_start = file_info64.disk_num_start; nuclear@0: pfile_info->internal_fa = file_info64.internal_fa; nuclear@0: pfile_info->external_fa = file_info64.external_fa; nuclear@0: nuclear@0: pfile_info->tmu_date = file_info64.tmu_date, nuclear@0: nuclear@0: nuclear@0: pfile_info->compressed_size = (uLong)file_info64.compressed_size; nuclear@0: pfile_info->uncompressed_size = (uLong)file_info64.uncompressed_size; nuclear@0: nuclear@0: } nuclear@0: return err; nuclear@0: } nuclear@0: /* nuclear@0: Set the current file of the zipfile to the first file. nuclear@0: return UNZ_OK if there is no problem nuclear@0: */ nuclear@0: extern int ZEXPORT unzGoToFirstFile (unzFile file) nuclear@0: { nuclear@0: int err=UNZ_OK; nuclear@0: unz64_s* s; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: s->pos_in_central_dir=s->offset_central_dir; nuclear@0: s->num_file=0; nuclear@0: err=unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, nuclear@0: &s->cur_file_info_internal, nuclear@0: NULL,0,NULL,0,NULL,0); nuclear@0: s->current_file_ok = (err == UNZ_OK); nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: Set the current file of the zipfile to the next file. nuclear@0: return UNZ_OK if there is no problem nuclear@0: return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest. nuclear@0: */ nuclear@0: extern int ZEXPORT unzGoToNextFile (unzFile file) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: int err; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: if (!s->current_file_ok) nuclear@0: return UNZ_END_OF_LIST_OF_FILE; nuclear@0: if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ nuclear@0: if (s->num_file+1==s->gi.number_entry) nuclear@0: return UNZ_END_OF_LIST_OF_FILE; nuclear@0: nuclear@0: s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + nuclear@0: s->cur_file_info.size_file_extra + s->cur_file_info.size_file_comment ; nuclear@0: s->num_file++; nuclear@0: err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, nuclear@0: &s->cur_file_info_internal, nuclear@0: NULL,0,NULL,0,NULL,0); nuclear@0: s->current_file_ok = (err == UNZ_OK); nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Try locate the file szFileName in the zipfile. nuclear@0: For the iCaseSensitivity signification, see unzipStringFileNameCompare nuclear@0: nuclear@0: return value : nuclear@0: UNZ_OK if the file is found. It becomes the current file. nuclear@0: UNZ_END_OF_LIST_OF_FILE if the file is not found nuclear@0: */ nuclear@0: extern int ZEXPORT unzLocateFile (unzFile file, const char *szFileName, int iCaseSensitivity) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: int err; nuclear@0: nuclear@0: /* We remember the 'current' position in the file so that we can jump nuclear@0: * back there if we fail. nuclear@0: */ nuclear@0: unz_file_info64 cur_file_infoSaved; nuclear@0: unz_file_info64_internal cur_file_info_internalSaved; nuclear@0: ZPOS64_T num_fileSaved; nuclear@0: ZPOS64_T pos_in_central_dirSaved; nuclear@0: nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: if (strlen(szFileName)>=UNZ_MAXFILENAMEINZIP) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: s=(unz64_s*)file; nuclear@0: if (!s->current_file_ok) nuclear@0: return UNZ_END_OF_LIST_OF_FILE; nuclear@0: nuclear@0: /* Save the current state */ nuclear@0: num_fileSaved = s->num_file; nuclear@0: pos_in_central_dirSaved = s->pos_in_central_dir; nuclear@0: cur_file_infoSaved = s->cur_file_info; nuclear@0: cur_file_info_internalSaved = s->cur_file_info_internal; nuclear@0: nuclear@0: err = unzGoToFirstFile(file); nuclear@0: nuclear@0: while (err == UNZ_OK) nuclear@0: { nuclear@0: char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1]; nuclear@0: err = unzGetCurrentFileInfo64(file,NULL, nuclear@0: szCurrentFileName,sizeof(szCurrentFileName)-1, nuclear@0: NULL,0,NULL,0); nuclear@0: if (err == UNZ_OK) nuclear@0: { nuclear@0: if (unzStringFileNameCompare(szCurrentFileName, nuclear@0: szFileName,iCaseSensitivity)==0) nuclear@0: return UNZ_OK; nuclear@0: err = unzGoToNextFile(file); nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: /* We failed, so restore the state of the 'current file' to where we nuclear@0: * were. nuclear@0: */ nuclear@0: s->num_file = num_fileSaved ; nuclear@0: s->pos_in_central_dir = pos_in_central_dirSaved ; nuclear@0: s->cur_file_info = cur_file_infoSaved; nuclear@0: s->cur_file_info_internal = cur_file_info_internalSaved; nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: /////////////////////////////////////////// nuclear@0: // Contributed by Ryan Haksi (mailto://cryogen@infoserve.net) nuclear@0: // I need random access nuclear@0: // nuclear@0: // Further optimization could be realized by adding an ability nuclear@0: // to cache the directory in memory. The goal being a single nuclear@0: // comprehensive file read to put the file I need in a memory. nuclear@0: */ nuclear@0: nuclear@0: /* nuclear@0: typedef struct unz_file_pos_s nuclear@0: { nuclear@0: ZPOS64_T pos_in_zip_directory; // offset in file nuclear@0: ZPOS64_T num_of_file; // # of file nuclear@0: } unz_file_pos; nuclear@0: */ nuclear@0: nuclear@0: extern int ZEXPORT unzGetFilePos64(unzFile file, unz64_file_pos* file_pos) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: nuclear@0: if (file==NULL || file_pos==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: if (!s->current_file_ok) nuclear@0: return UNZ_END_OF_LIST_OF_FILE; nuclear@0: nuclear@0: file_pos->pos_in_zip_directory = s->pos_in_central_dir; nuclear@0: file_pos->num_of_file = s->num_file; nuclear@0: nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzGetFilePos( nuclear@0: unzFile file, nuclear@0: unz_file_pos* file_pos) nuclear@0: { nuclear@0: unz64_file_pos file_pos64; nuclear@0: int err = unzGetFilePos64(file,&file_pos64); nuclear@0: if (err==UNZ_OK) nuclear@0: { nuclear@0: file_pos->pos_in_zip_directory = (uLong)file_pos64.pos_in_zip_directory; nuclear@0: file_pos->num_of_file = (uLong)file_pos64.num_of_file; nuclear@0: } nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzGoToFilePos64(unzFile file, const unz64_file_pos* file_pos) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: int err; nuclear@0: nuclear@0: if (file==NULL || file_pos==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: nuclear@0: /* jump to the right spot */ nuclear@0: s->pos_in_central_dir = file_pos->pos_in_zip_directory; nuclear@0: s->num_file = file_pos->num_of_file; nuclear@0: nuclear@0: /* set the current file */ nuclear@0: err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, nuclear@0: &s->cur_file_info_internal, nuclear@0: NULL,0,NULL,0,NULL,0); nuclear@0: /* return results */ nuclear@0: s->current_file_ok = (err == UNZ_OK); nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzGoToFilePos( nuclear@0: unzFile file, nuclear@0: unz_file_pos* file_pos) nuclear@0: { nuclear@0: unz64_file_pos file_pos64; nuclear@0: if (file_pos == NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: file_pos64.pos_in_zip_directory = file_pos->pos_in_zip_directory; nuclear@0: file_pos64.num_of_file = file_pos->num_of_file; nuclear@0: return unzGoToFilePos64(file,&file_pos64); nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: // Unzip Helper Functions - should be here? nuclear@0: /////////////////////////////////////////// nuclear@0: */ nuclear@0: nuclear@0: /* nuclear@0: Read the local header of the current zipfile nuclear@0: Check the coherency of the local header and info in the end of central nuclear@0: directory about this file nuclear@0: store in *piSizeVar the size of extra info in local header nuclear@0: (filename and size of extra field data) nuclear@0: */ nuclear@0: local int unz64local_CheckCurrentFileCoherencyHeader (unz64_s* s, uInt* piSizeVar, nuclear@0: ZPOS64_T * poffset_local_extrafield, nuclear@0: uInt * psize_local_extrafield) nuclear@0: { nuclear@0: uLong uMagic,uData,uFlags; nuclear@0: uLong size_filename; nuclear@0: uLong size_extra_field; nuclear@0: int err=UNZ_OK; nuclear@0: nuclear@0: *piSizeVar = 0; nuclear@0: *poffset_local_extrafield = 0; nuclear@0: *psize_local_extrafield = 0; nuclear@0: nuclear@0: if (ZSEEK64(s->z_filefunc, s->filestream,s->cur_file_info_internal.offset_curfile + nuclear@0: s->byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return UNZ_ERRNO; nuclear@0: nuclear@0: nuclear@0: if (err==UNZ_OK) nuclear@0: { nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uMagic) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: else if (uMagic!=0x04034b50) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: } nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: /* nuclear@0: else if ((err==UNZ_OK) && (uData!=s->cur_file_info.wVersion)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: */ nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&uFlags) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: else if ((err==UNZ_OK) && (uData!=s->cur_file_info.compression_method)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: if ((err==UNZ_OK) && (s->cur_file_info.compression_method!=0) && nuclear@0: /* #ifdef HAVE_BZIP2 */ nuclear@0: (s->cur_file_info.compression_method!=Z_BZIP2ED) && nuclear@0: /* #endif */ nuclear@0: (s->cur_file_info.compression_method!=Z_DEFLATED)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* date/time */ nuclear@0: err=UNZ_ERRNO; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* crc */ nuclear@0: err=UNZ_ERRNO; nuclear@0: else if ((err==UNZ_OK) && (uData!=s->cur_file_info.crc) && ((uFlags & 8)==0)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size compr */ nuclear@0: err=UNZ_ERRNO; nuclear@0: else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.compressed_size) && ((uFlags & 8)==0)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: if (unz64local_getLong(&s->z_filefunc, s->filestream,&uData) != UNZ_OK) /* size uncompr */ nuclear@0: err=UNZ_ERRNO; nuclear@0: else if (uData != 0xFFFFFFFF && (err==UNZ_OK) && (uData!=s->cur_file_info.uncompressed_size) && ((uFlags & 8)==0)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_filename) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: else if ((err==UNZ_OK) && (size_filename!=s->cur_file_info.size_filename)) nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: *piSizeVar += (uInt)size_filename; nuclear@0: nuclear@0: if (unz64local_getShort(&s->z_filefunc, s->filestream,&size_extra_field) != UNZ_OK) nuclear@0: err=UNZ_ERRNO; nuclear@0: *poffset_local_extrafield= s->cur_file_info_internal.offset_curfile + nuclear@0: SIZEZIPLOCALHEADER + size_filename; nuclear@0: *psize_local_extrafield = (uInt)size_extra_field; nuclear@0: nuclear@0: *piSizeVar += (uInt)size_extra_field; nuclear@0: nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: Open for reading data the current file in the zipfile. nuclear@0: If there is no error and the file is opened, the return value is UNZ_OK. nuclear@0: */ nuclear@0: extern int ZEXPORT unzOpenCurrentFile3 (unzFile file, int* method, nuclear@0: int* level, int raw, const char* password) nuclear@0: { nuclear@0: int err=UNZ_OK; nuclear@0: uInt iSizeVar; nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: ZPOS64_T offset_local_extrafield; /* offset of the local extra field */ nuclear@0: uInt size_local_extrafield; /* size of the local extra field */ nuclear@0: # ifndef NOUNCRYPT nuclear@0: char source[12]; nuclear@0: # else nuclear@0: if (password != NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: # endif nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: if (!s->current_file_ok) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: if (s->pfile_in_zip_read != NULL) nuclear@0: unzCloseCurrentFile(file); nuclear@0: nuclear@0: if (unz64local_CheckCurrentFileCoherencyHeader(s,&iSizeVar, &offset_local_extrafield,&size_local_extrafield)!=UNZ_OK) nuclear@0: return UNZ_BADZIPFILE; nuclear@0: nuclear@0: pfile_in_zip_read_info = (file_in_zip64_read_info_s*)ALLOC(sizeof(file_in_zip64_read_info_s)); nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_INTERNALERROR; nuclear@0: nuclear@0: pfile_in_zip_read_info->read_buffer=(char*)ALLOC(UNZ_BUFSIZE); nuclear@0: pfile_in_zip_read_info->offset_local_extrafield = offset_local_extrafield; nuclear@0: pfile_in_zip_read_info->size_local_extrafield = size_local_extrafield; nuclear@0: pfile_in_zip_read_info->pos_local_extrafield=0; nuclear@0: pfile_in_zip_read_info->raw=raw; nuclear@0: nuclear@0: if (pfile_in_zip_read_info->read_buffer==NULL) nuclear@0: { nuclear@0: TRYFREE(pfile_in_zip_read_info); nuclear@0: return UNZ_INTERNALERROR; nuclear@0: } nuclear@0: nuclear@0: pfile_in_zip_read_info->stream_initialised=0; nuclear@0: nuclear@0: if (method!=NULL) nuclear@0: *method = (int)s->cur_file_info.compression_method; nuclear@0: nuclear@0: if (level!=NULL) nuclear@0: { nuclear@0: *level = 6; nuclear@0: switch (s->cur_file_info.flag & 0x06) nuclear@0: { nuclear@0: case 6 : *level = 1; break; nuclear@0: case 4 : *level = 2; break; nuclear@0: case 2 : *level = 9; break; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: if ((s->cur_file_info.compression_method!=0) && nuclear@0: /* #ifdef HAVE_BZIP2 */ nuclear@0: (s->cur_file_info.compression_method!=Z_BZIP2ED) && nuclear@0: /* #endif */ nuclear@0: (s->cur_file_info.compression_method!=Z_DEFLATED)) nuclear@0: nuclear@0: err=UNZ_BADZIPFILE; nuclear@0: nuclear@0: pfile_in_zip_read_info->crc32_wait=s->cur_file_info.crc; nuclear@0: pfile_in_zip_read_info->crc32=0; nuclear@0: pfile_in_zip_read_info->total_out_64=0; nuclear@0: pfile_in_zip_read_info->compression_method = s->cur_file_info.compression_method; nuclear@0: pfile_in_zip_read_info->filestream=s->filestream; nuclear@0: pfile_in_zip_read_info->z_filefunc=s->z_filefunc; nuclear@0: pfile_in_zip_read_info->byte_before_the_zipfile=s->byte_before_the_zipfile; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.total_out = 0; nuclear@0: nuclear@0: if ((s->cur_file_info.compression_method==Z_BZIP2ED) && (!raw)) nuclear@0: { nuclear@0: #ifdef HAVE_BZIP2 nuclear@0: pfile_in_zip_read_info->bstream.bzalloc = (void *(*) (void *, int, int))0; nuclear@0: pfile_in_zip_read_info->bstream.bzfree = (free_func)0; nuclear@0: pfile_in_zip_read_info->bstream.opaque = (voidpf)0; nuclear@0: pfile_in_zip_read_info->bstream.state = (voidpf)0; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; nuclear@0: pfile_in_zip_read_info->stream.zfree = (free_func)0; nuclear@0: pfile_in_zip_read_info->stream.opaque = (voidpf)0; nuclear@0: pfile_in_zip_read_info->stream.next_in = (voidpf)0; nuclear@0: pfile_in_zip_read_info->stream.avail_in = 0; nuclear@0: nuclear@0: err=BZ2_bzDecompressInit(&pfile_in_zip_read_info->bstream, 0, 0); nuclear@0: if (err == Z_OK) nuclear@0: pfile_in_zip_read_info->stream_initialised=Z_BZIP2ED; nuclear@0: else nuclear@0: { nuclear@0: TRYFREE(pfile_in_zip_read_info); nuclear@0: return err; nuclear@0: } nuclear@0: #else nuclear@0: pfile_in_zip_read_info->raw=1; nuclear@0: #endif nuclear@0: } nuclear@0: else if ((s->cur_file_info.compression_method==Z_DEFLATED) && (!raw)) nuclear@0: { nuclear@0: pfile_in_zip_read_info->stream.zalloc = (alloc_func)0; nuclear@0: pfile_in_zip_read_info->stream.zfree = (free_func)0; nuclear@0: pfile_in_zip_read_info->stream.opaque = (voidpf)0; nuclear@0: pfile_in_zip_read_info->stream.next_in = 0; nuclear@0: pfile_in_zip_read_info->stream.avail_in = 0; nuclear@0: nuclear@0: err=inflateInit2(&pfile_in_zip_read_info->stream, -MAX_WBITS); nuclear@0: if (err == Z_OK) nuclear@0: pfile_in_zip_read_info->stream_initialised=Z_DEFLATED; nuclear@0: else nuclear@0: { nuclear@0: TRYFREE(pfile_in_zip_read_info); nuclear@0: return err; nuclear@0: } nuclear@0: /* windowBits is passed < 0 to tell that there is no zlib header. nuclear@0: * Note that in this case inflate *requires* an extra "dummy" byte nuclear@0: * after the compressed stream in order to complete decompression and nuclear@0: * return Z_STREAM_END. nuclear@0: * In unzip, i don't wait absolutely Z_STREAM_END because I known the nuclear@0: * size of both compressed and uncompressed data nuclear@0: */ nuclear@0: } nuclear@0: pfile_in_zip_read_info->rest_read_compressed = nuclear@0: s->cur_file_info.compressed_size ; nuclear@0: pfile_in_zip_read_info->rest_read_uncompressed = nuclear@0: s->cur_file_info.uncompressed_size ; nuclear@0: nuclear@0: nuclear@0: pfile_in_zip_read_info->pos_in_zipfile = nuclear@0: s->cur_file_info_internal.offset_curfile + SIZEZIPLOCALHEADER + nuclear@0: iSizeVar; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.avail_in = (uInt)0; nuclear@0: nuclear@0: s->pfile_in_zip_read = pfile_in_zip_read_info; nuclear@0: s->encrypted = 0; nuclear@0: nuclear@0: # ifndef NOUNCRYPT nuclear@0: if (password != NULL) nuclear@0: { nuclear@0: int i; nuclear@0: s->pcrc_32_tab = get_crc_table(); nuclear@0: init_keys(password,s->keys,s->pcrc_32_tab); nuclear@0: if (ZSEEK64(s->z_filefunc, s->filestream, nuclear@0: s->pfile_in_zip_read->pos_in_zipfile + nuclear@0: s->pfile_in_zip_read->byte_before_the_zipfile, nuclear@0: SEEK_SET)!=0) nuclear@0: return UNZ_INTERNALERROR; nuclear@0: if(ZREAD64(s->z_filefunc, s->filestream,source, 12)<12) nuclear@0: return UNZ_INTERNALERROR; nuclear@0: nuclear@0: for (i = 0; i<12; i++) nuclear@0: zdecode(s->keys,s->pcrc_32_tab,source[i]); nuclear@0: nuclear@0: s->pfile_in_zip_read->pos_in_zipfile+=12; nuclear@0: s->encrypted=1; nuclear@0: } nuclear@0: # endif nuclear@0: nuclear@0: nuclear@0: return UNZ_OK; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzOpenCurrentFile (unzFile file) nuclear@0: { nuclear@0: return unzOpenCurrentFile3(file, NULL, NULL, 0, NULL); nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzOpenCurrentFilePassword (unzFile file, const char* password) nuclear@0: { nuclear@0: return unzOpenCurrentFile3(file, NULL, NULL, 0, password); nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzOpenCurrentFile2 (unzFile file, int* method, int* level, int raw) nuclear@0: { nuclear@0: return unzOpenCurrentFile3(file, method, level, raw, NULL); nuclear@0: } nuclear@0: nuclear@0: /** Addition for GDAL : START */ nuclear@0: nuclear@0: extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64( unzFile file) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: s=(unz64_s*)file; nuclear@0: if (file==NULL) nuclear@0: return 0; //UNZ_PARAMERROR; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return 0; //UNZ_PARAMERROR; nuclear@0: return pfile_in_zip_read_info->pos_in_zipfile + nuclear@0: pfile_in_zip_read_info->byte_before_the_zipfile; nuclear@0: } nuclear@0: nuclear@0: /** Addition for GDAL : END */ nuclear@0: nuclear@0: /* nuclear@0: Read bytes from the current file. nuclear@0: buf contain buffer where data must be copied nuclear@0: len the size of buf. nuclear@0: nuclear@0: return the number of byte copied if somes bytes are copied nuclear@0: return 0 if the end of file was reached nuclear@0: return <0 with error code if there is an error nuclear@0: (UNZ_ERRNO for IO error, or zLib error for uncompress error) nuclear@0: */ nuclear@0: extern int ZEXPORT unzReadCurrentFile (unzFile file, voidp buf, unsigned len) nuclear@0: { nuclear@0: int err=UNZ_OK; nuclear@0: uInt iRead = 0; nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: nuclear@0: if (pfile_in_zip_read_info->read_buffer == NULL) nuclear@0: return UNZ_END_OF_LIST_OF_FILE; nuclear@0: if (len==0) nuclear@0: return 0; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.next_out = (Bytef*)buf; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.avail_out = (uInt)len; nuclear@0: nuclear@0: if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && nuclear@0: (!(pfile_in_zip_read_info->raw))) nuclear@0: pfile_in_zip_read_info->stream.avail_out = nuclear@0: (uInt)pfile_in_zip_read_info->rest_read_uncompressed; nuclear@0: nuclear@0: if ((len>pfile_in_zip_read_info->rest_read_compressed+ nuclear@0: pfile_in_zip_read_info->stream.avail_in) && nuclear@0: (pfile_in_zip_read_info->raw)) nuclear@0: pfile_in_zip_read_info->stream.avail_out = nuclear@0: (uInt)pfile_in_zip_read_info->rest_read_compressed+ nuclear@0: pfile_in_zip_read_info->stream.avail_in; nuclear@0: nuclear@0: while (pfile_in_zip_read_info->stream.avail_out>0) nuclear@0: { nuclear@0: if ((pfile_in_zip_read_info->stream.avail_in==0) && nuclear@0: (pfile_in_zip_read_info->rest_read_compressed>0)) nuclear@0: { nuclear@0: uInt uReadThis = UNZ_BUFSIZE; nuclear@0: if (pfile_in_zip_read_info->rest_read_compressedrest_read_compressed; nuclear@0: if (uReadThis == 0) nuclear@0: return UNZ_EOF; nuclear@0: if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, nuclear@0: pfile_in_zip_read_info->filestream, nuclear@0: pfile_in_zip_read_info->pos_in_zipfile + nuclear@0: pfile_in_zip_read_info->byte_before_the_zipfile, nuclear@0: ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return UNZ_ERRNO; nuclear@0: if (ZREAD64(pfile_in_zip_read_info->z_filefunc, nuclear@0: pfile_in_zip_read_info->filestream, nuclear@0: pfile_in_zip_read_info->read_buffer, nuclear@0: uReadThis)!=uReadThis) nuclear@0: return UNZ_ERRNO; nuclear@0: nuclear@0: nuclear@0: # ifndef NOUNCRYPT nuclear@0: if(s->encrypted) nuclear@0: { nuclear@0: uInt i; nuclear@0: for(i=0;iread_buffer[i] = nuclear@0: zdecode(s->keys,s->pcrc_32_tab, nuclear@0: pfile_in_zip_read_info->read_buffer[i]); nuclear@0: } nuclear@0: # endif nuclear@0: nuclear@0: nuclear@0: pfile_in_zip_read_info->pos_in_zipfile += uReadThis; nuclear@0: nuclear@0: pfile_in_zip_read_info->rest_read_compressed-=uReadThis; nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.next_in = nuclear@0: (Bytef*)pfile_in_zip_read_info->read_buffer; nuclear@0: pfile_in_zip_read_info->stream.avail_in = (uInt)uReadThis; nuclear@0: } nuclear@0: nuclear@0: if ((pfile_in_zip_read_info->compression_method==0) || (pfile_in_zip_read_info->raw)) nuclear@0: { nuclear@0: uInt uDoCopy,i ; nuclear@0: nuclear@0: if ((pfile_in_zip_read_info->stream.avail_in == 0) && nuclear@0: (pfile_in_zip_read_info->rest_read_compressed == 0)) nuclear@0: return (iRead==0) ? UNZ_EOF : iRead; nuclear@0: nuclear@0: if (pfile_in_zip_read_info->stream.avail_out < nuclear@0: pfile_in_zip_read_info->stream.avail_in) nuclear@0: uDoCopy = pfile_in_zip_read_info->stream.avail_out ; nuclear@0: else nuclear@0: uDoCopy = pfile_in_zip_read_info->stream.avail_in ; nuclear@0: nuclear@0: for (i=0;istream.next_out+i) = nuclear@0: *(pfile_in_zip_read_info->stream.next_in+i); nuclear@0: nuclear@0: pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uDoCopy; nuclear@0: nuclear@0: pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32, nuclear@0: pfile_in_zip_read_info->stream.next_out, nuclear@0: uDoCopy); nuclear@0: pfile_in_zip_read_info->rest_read_uncompressed-=uDoCopy; nuclear@0: pfile_in_zip_read_info->stream.avail_in -= uDoCopy; nuclear@0: pfile_in_zip_read_info->stream.avail_out -= uDoCopy; nuclear@0: pfile_in_zip_read_info->stream.next_out += uDoCopy; nuclear@0: pfile_in_zip_read_info->stream.next_in += uDoCopy; nuclear@0: pfile_in_zip_read_info->stream.total_out += uDoCopy; nuclear@0: iRead += uDoCopy; nuclear@0: } nuclear@0: else if (pfile_in_zip_read_info->compression_method==Z_BZIP2ED) nuclear@0: { nuclear@0: #ifdef HAVE_BZIP2 nuclear@0: uLong uTotalOutBefore,uTotalOutAfter; nuclear@0: const Bytef *bufBefore; nuclear@0: uLong uOutThis; nuclear@0: nuclear@0: pfile_in_zip_read_info->bstream.next_in = (char*)pfile_in_zip_read_info->stream.next_in; nuclear@0: pfile_in_zip_read_info->bstream.avail_in = pfile_in_zip_read_info->stream.avail_in; nuclear@0: pfile_in_zip_read_info->bstream.total_in_lo32 = pfile_in_zip_read_info->stream.total_in; nuclear@0: pfile_in_zip_read_info->bstream.total_in_hi32 = 0; nuclear@0: pfile_in_zip_read_info->bstream.next_out = (char*)pfile_in_zip_read_info->stream.next_out; nuclear@0: pfile_in_zip_read_info->bstream.avail_out = pfile_in_zip_read_info->stream.avail_out; nuclear@0: pfile_in_zip_read_info->bstream.total_out_lo32 = pfile_in_zip_read_info->stream.total_out; nuclear@0: pfile_in_zip_read_info->bstream.total_out_hi32 = 0; nuclear@0: nuclear@0: uTotalOutBefore = pfile_in_zip_read_info->bstream.total_out_lo32; nuclear@0: bufBefore = (const Bytef *)pfile_in_zip_read_info->bstream.next_out; nuclear@0: nuclear@0: err=BZ2_bzDecompress(&pfile_in_zip_read_info->bstream); nuclear@0: nuclear@0: uTotalOutAfter = pfile_in_zip_read_info->bstream.total_out_lo32; nuclear@0: uOutThis = uTotalOutAfter-uTotalOutBefore; nuclear@0: nuclear@0: pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; nuclear@0: nuclear@0: pfile_in_zip_read_info->crc32 = crc32(pfile_in_zip_read_info->crc32,bufBefore, (uInt)(uOutThis)); nuclear@0: pfile_in_zip_read_info->rest_read_uncompressed -= uOutThis; nuclear@0: iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); nuclear@0: nuclear@0: pfile_in_zip_read_info->stream.next_in = (Bytef*)pfile_in_zip_read_info->bstream.next_in; nuclear@0: pfile_in_zip_read_info->stream.avail_in = pfile_in_zip_read_info->bstream.avail_in; nuclear@0: pfile_in_zip_read_info->stream.total_in = pfile_in_zip_read_info->bstream.total_in_lo32; nuclear@0: pfile_in_zip_read_info->stream.next_out = (Bytef*)pfile_in_zip_read_info->bstream.next_out; nuclear@0: pfile_in_zip_read_info->stream.avail_out = pfile_in_zip_read_info->bstream.avail_out; nuclear@0: pfile_in_zip_read_info->stream.total_out = pfile_in_zip_read_info->bstream.total_out_lo32; nuclear@0: nuclear@0: if (err==BZ_STREAM_END) nuclear@0: return (iRead==0) ? UNZ_EOF : iRead; nuclear@0: if (err!=BZ_OK) nuclear@0: break; nuclear@0: #endif nuclear@0: } // end Z_BZIP2ED nuclear@0: else nuclear@0: { nuclear@0: ZPOS64_T uTotalOutBefore,uTotalOutAfter; nuclear@0: const Bytef *bufBefore; nuclear@0: ZPOS64_T uOutThis; nuclear@0: int flush=Z_SYNC_FLUSH; nuclear@0: nuclear@0: uTotalOutBefore = pfile_in_zip_read_info->stream.total_out; nuclear@0: bufBefore = pfile_in_zip_read_info->stream.next_out; nuclear@0: nuclear@0: /* nuclear@0: if ((pfile_in_zip_read_info->rest_read_uncompressed == nuclear@0: pfile_in_zip_read_info->stream.avail_out) && nuclear@0: (pfile_in_zip_read_info->rest_read_compressed == 0)) nuclear@0: flush = Z_FINISH; nuclear@0: */ nuclear@0: err=inflate(&pfile_in_zip_read_info->stream,flush); nuclear@0: nuclear@0: if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) nuclear@0: err = Z_DATA_ERROR; nuclear@0: nuclear@0: uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; nuclear@0: uOutThis = uTotalOutAfter-uTotalOutBefore; nuclear@0: nuclear@0: pfile_in_zip_read_info->total_out_64 = pfile_in_zip_read_info->total_out_64 + uOutThis; nuclear@0: nuclear@0: pfile_in_zip_read_info->crc32 = nuclear@0: crc32(pfile_in_zip_read_info->crc32,bufBefore, nuclear@0: (uInt)(uOutThis)); nuclear@0: nuclear@0: pfile_in_zip_read_info->rest_read_uncompressed -= nuclear@0: uOutThis; nuclear@0: nuclear@0: iRead += (uInt)(uTotalOutAfter - uTotalOutBefore); nuclear@0: nuclear@0: if (err==Z_STREAM_END) nuclear@0: return (iRead==0) ? UNZ_EOF : iRead; nuclear@0: if (err!=Z_OK) nuclear@0: break; nuclear@0: } nuclear@0: } nuclear@0: nuclear@0: if (err==Z_OK) nuclear@0: return iRead; nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Give the current position in uncompressed data nuclear@0: */ nuclear@0: extern z_off_t ZEXPORT unztell (unzFile file) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: return (z_off_t)pfile_in_zip_read_info->stream.total_out; nuclear@0: } nuclear@0: nuclear@0: extern ZPOS64_T ZEXPORT unztell64 (unzFile file) nuclear@0: { nuclear@0: nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: if (file==NULL) nuclear@0: return (ZPOS64_T)-1; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return (ZPOS64_T)-1; nuclear@0: nuclear@0: return pfile_in_zip_read_info->total_out_64; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: return 1 if the end of file was reached, 0 elsewhere nuclear@0: */ nuclear@0: extern int ZEXPORT unzeof (unzFile file) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: if (pfile_in_zip_read_info->rest_read_uncompressed == 0) nuclear@0: return 1; nuclear@0: else nuclear@0: return 0; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Read extra field from the current file (opened by unzOpenCurrentFile) nuclear@0: This is the local-header version of the extra field (sometimes, there is nuclear@0: more info in the local-header version than in the central-header) nuclear@0: nuclear@0: if buf==NULL, it return the size of the local extra field that can be read nuclear@0: nuclear@0: if buf!=NULL, len is the size of the buffer, the extra header is copied in nuclear@0: buf. nuclear@0: the return value is the number of bytes copied in buf, or (if <0) nuclear@0: the error code nuclear@0: */ nuclear@0: extern int ZEXPORT unzGetLocalExtrafield (unzFile file, voidp buf, unsigned len) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: uInt read_now; nuclear@0: ZPOS64_T size_to_read; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: size_to_read = (pfile_in_zip_read_info->size_local_extrafield - nuclear@0: pfile_in_zip_read_info->pos_local_extrafield); nuclear@0: nuclear@0: if (buf==NULL) nuclear@0: return (int)size_to_read; nuclear@0: nuclear@0: if (len>size_to_read) nuclear@0: read_now = (uInt)size_to_read; nuclear@0: else nuclear@0: read_now = (uInt)len ; nuclear@0: nuclear@0: if (read_now==0) nuclear@0: return 0; nuclear@0: nuclear@0: if (ZSEEK64(pfile_in_zip_read_info->z_filefunc, nuclear@0: pfile_in_zip_read_info->filestream, nuclear@0: pfile_in_zip_read_info->offset_local_extrafield + nuclear@0: pfile_in_zip_read_info->pos_local_extrafield, nuclear@0: ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return UNZ_ERRNO; nuclear@0: nuclear@0: if (ZREAD64(pfile_in_zip_read_info->z_filefunc, nuclear@0: pfile_in_zip_read_info->filestream, nuclear@0: buf,read_now)!=read_now) nuclear@0: return UNZ_ERRNO; nuclear@0: nuclear@0: return (int)read_now; nuclear@0: } nuclear@0: nuclear@0: /* nuclear@0: Close the file in zip opened with unzipOpenCurrentFile nuclear@0: Return UNZ_CRCERROR if all the file was read but the CRC is not good nuclear@0: */ nuclear@0: extern int ZEXPORT unzCloseCurrentFile (unzFile file) nuclear@0: { nuclear@0: int err=UNZ_OK; nuclear@0: nuclear@0: unz64_s* s; nuclear@0: file_in_zip64_read_info_s* pfile_in_zip_read_info; nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: pfile_in_zip_read_info=s->pfile_in_zip_read; nuclear@0: nuclear@0: if (pfile_in_zip_read_info==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: nuclear@0: nuclear@0: if ((pfile_in_zip_read_info->rest_read_uncompressed == 0) && nuclear@0: (!pfile_in_zip_read_info->raw)) nuclear@0: { nuclear@0: if (pfile_in_zip_read_info->crc32 != pfile_in_zip_read_info->crc32_wait) nuclear@0: err=UNZ_CRCERROR; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: TRYFREE(pfile_in_zip_read_info->read_buffer); nuclear@0: pfile_in_zip_read_info->read_buffer = NULL; nuclear@0: if (pfile_in_zip_read_info->stream_initialised == Z_DEFLATED) nuclear@0: inflateEnd(&pfile_in_zip_read_info->stream); nuclear@0: #ifdef HAVE_BZIP2 nuclear@0: else if (pfile_in_zip_read_info->stream_initialised == Z_BZIP2ED) nuclear@0: BZ2_bzDecompressEnd(&pfile_in_zip_read_info->bstream); nuclear@0: #endif nuclear@0: nuclear@0: nuclear@0: pfile_in_zip_read_info->stream_initialised = 0; nuclear@0: TRYFREE(pfile_in_zip_read_info); nuclear@0: nuclear@0: s->pfile_in_zip_read=NULL; nuclear@0: nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: nuclear@0: /* nuclear@0: Get the global comment string of the ZipFile, in the szComment buffer. nuclear@0: uSizeBuf is the size of the szComment buffer. nuclear@0: return the number of byte copied or an error code <0 nuclear@0: */ nuclear@0: extern int ZEXPORT unzGetGlobalComment (unzFile file, char * szComment, uLong uSizeBuf) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: uLong uReadThis ; nuclear@0: if (file==NULL) nuclear@0: return (int)UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: nuclear@0: uReadThis = uSizeBuf; nuclear@0: if (uReadThis>s->gi.size_comment) nuclear@0: uReadThis = s->gi.size_comment; nuclear@0: nuclear@0: if (ZSEEK64(s->z_filefunc,s->filestream,s->central_pos+22,ZLIB_FILEFUNC_SEEK_SET)!=0) nuclear@0: return UNZ_ERRNO; nuclear@0: nuclear@0: if (uReadThis>0) nuclear@0: { nuclear@0: *szComment='\0'; nuclear@0: if (ZREAD64(s->z_filefunc,s->filestream,szComment,uReadThis)!=uReadThis) nuclear@0: return UNZ_ERRNO; nuclear@0: } nuclear@0: nuclear@0: if ((szComment != NULL) && (uSizeBuf > s->gi.size_comment)) nuclear@0: *(szComment+s->gi.size_comment)='\0'; nuclear@0: return (int)uReadThis; nuclear@0: } nuclear@0: nuclear@0: /* Additions by RX '2004 */ nuclear@0: extern ZPOS64_T ZEXPORT unzGetOffset64(unzFile file) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return 0; //UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: if (!s->current_file_ok) nuclear@0: return 0; nuclear@0: if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) nuclear@0: if (s->num_file==s->gi.number_entry) nuclear@0: return 0; nuclear@0: return s->pos_in_central_dir; nuclear@0: } nuclear@0: nuclear@0: extern uLong ZEXPORT unzGetOffset (unzFile file) nuclear@0: { nuclear@0: ZPOS64_T offset64; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return 0; //UNZ_PARAMERROR; nuclear@0: offset64 = unzGetOffset64(file); nuclear@0: return (uLong)offset64; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzSetOffset64(unzFile file, ZPOS64_T pos) nuclear@0: { nuclear@0: unz64_s* s; nuclear@0: int err; nuclear@0: nuclear@0: if (file==NULL) nuclear@0: return UNZ_PARAMERROR; nuclear@0: s=(unz64_s*)file; nuclear@0: nuclear@0: s->pos_in_central_dir = pos; nuclear@0: s->num_file = s->gi.number_entry; /* hack */ nuclear@0: err = unz64local_GetCurrentFileInfoInternal(file,&s->cur_file_info, nuclear@0: &s->cur_file_info_internal, nuclear@0: NULL,0,NULL,0,NULL,0); nuclear@0: s->current_file_ok = (err == UNZ_OK); nuclear@0: return err; nuclear@0: } nuclear@0: nuclear@0: extern int ZEXPORT unzSetOffset (unzFile file, uLong pos) nuclear@0: { nuclear@0: return unzSetOffset64(file,pos); nuclear@0: }