xref: /netbsd-src/external/gpl3/binutils/dist/zlib/contrib/minizip/unzip.h (revision 4f645668ed707e1f969c546666f8c8e45e6f8888)
19573673dSchristos /* unzip.h -- IO for uncompress .zip files using zlib
29573673dSchristos    Version 1.1, February 14h, 2010
39573673dSchristos    part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
49573673dSchristos 
59573673dSchristos          Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
69573673dSchristos 
79573673dSchristos          Modifications of Unzip for Zip64
89573673dSchristos          Copyright (C) 2007-2008 Even Rouault
99573673dSchristos 
109573673dSchristos          Modifications for Zip64 support on both zip and unzip
119573673dSchristos          Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
129573673dSchristos 
139573673dSchristos          For more info read MiniZip_info.txt
149573673dSchristos 
159573673dSchristos          ---------------------------------------------------------------------------------
169573673dSchristos 
179573673dSchristos         Condition of use and distribution are the same than zlib :
189573673dSchristos 
199573673dSchristos   This software is provided 'as-is', without any express or implied
209573673dSchristos   warranty.  In no event will the authors be held liable for any damages
219573673dSchristos   arising from the use of this software.
229573673dSchristos 
239573673dSchristos   Permission is granted to anyone to use this software for any purpose,
249573673dSchristos   including commercial applications, and to alter it and redistribute it
259573673dSchristos   freely, subject to the following restrictions:
269573673dSchristos 
279573673dSchristos   1. The origin of this software must not be misrepresented; you must not
289573673dSchristos      claim that you wrote the original software. If you use this software
299573673dSchristos      in a product, an acknowledgment in the product documentation would be
309573673dSchristos      appreciated but is not required.
319573673dSchristos   2. Altered source versions must be plainly marked as such, and must not be
329573673dSchristos      misrepresented as being the original software.
339573673dSchristos   3. This notice may not be removed or altered from any source distribution.
349573673dSchristos 
359573673dSchristos   ---------------------------------------------------------------------------------
369573673dSchristos 
379573673dSchristos         Changes
389573673dSchristos 
399573673dSchristos         See header of unzip64.c
409573673dSchristos 
419573673dSchristos */
429573673dSchristos 
439573673dSchristos #ifndef _unz64_H
449573673dSchristos #define _unz64_H
459573673dSchristos 
469573673dSchristos #ifdef __cplusplus
479573673dSchristos extern "C" {
489573673dSchristos #endif
499573673dSchristos 
509573673dSchristos #ifndef _ZLIB_H
519573673dSchristos #include "zlib.h"
529573673dSchristos #endif
539573673dSchristos 
549573673dSchristos #ifndef  _ZLIBIOAPI_H
559573673dSchristos #include "ioapi.h"
569573673dSchristos #endif
579573673dSchristos 
589573673dSchristos #ifdef HAVE_BZIP2
599573673dSchristos #include "bzlib.h"
609573673dSchristos #endif
619573673dSchristos 
629573673dSchristos #define Z_BZIP2ED 12
639573673dSchristos 
649573673dSchristos #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
659573673dSchristos /* like the STRICT of WIN32, we define a pointer that cannot be converted
669573673dSchristos     from (void*) without cast */
679573673dSchristos typedef struct TagunzFile__ { int unused; } unzFile__;
689573673dSchristos typedef unzFile__ *unzFile;
699573673dSchristos #else
709573673dSchristos typedef voidp unzFile;
719573673dSchristos #endif
729573673dSchristos 
739573673dSchristos 
749573673dSchristos #define UNZ_OK                          (0)
759573673dSchristos #define UNZ_END_OF_LIST_OF_FILE         (-100)
769573673dSchristos #define UNZ_ERRNO                       (Z_ERRNO)
779573673dSchristos #define UNZ_EOF                         (0)
789573673dSchristos #define UNZ_PARAMERROR                  (-102)
799573673dSchristos #define UNZ_BADZIPFILE                  (-103)
809573673dSchristos #define UNZ_INTERNALERROR               (-104)
819573673dSchristos #define UNZ_CRCERROR                    (-105)
829573673dSchristos 
839573673dSchristos /* tm_unz contain date/time info */
849573673dSchristos typedef struct tm_unz_s
859573673dSchristos {
86*4f645668Schristos     int tm_sec;             /* seconds after the minute - [0,59] */
87*4f645668Schristos     int tm_min;             /* minutes after the hour - [0,59] */
88*4f645668Schristos     int tm_hour;            /* hours since midnight - [0,23] */
89*4f645668Schristos     int tm_mday;            /* day of the month - [1,31] */
90*4f645668Schristos     int tm_mon;             /* months since January - [0,11] */
91*4f645668Schristos     int tm_year;            /* years - [1980..2044] */
929573673dSchristos } tm_unz;
939573673dSchristos 
949573673dSchristos /* unz_global_info structure contain global data about the ZIPfile
959573673dSchristos    These data comes from the end of central dir */
969573673dSchristos typedef struct unz_global_info64_s
979573673dSchristos {
989573673dSchristos     ZPOS64_T number_entry;         /* total number of entries in
999573673dSchristos                                      the central dir on this disk */
1009573673dSchristos     uLong size_comment;         /* size of the global comment of the zipfile */
1019573673dSchristos } unz_global_info64;
1029573673dSchristos 
1039573673dSchristos typedef struct unz_global_info_s
1049573673dSchristos {
1059573673dSchristos     uLong number_entry;         /* total number of entries in
1069573673dSchristos                                      the central dir on this disk */
1079573673dSchristos     uLong size_comment;         /* size of the global comment of the zipfile */
1089573673dSchristos } unz_global_info;
1099573673dSchristos 
1109573673dSchristos /* unz_file_info contain information about a file in the zipfile */
1119573673dSchristos typedef struct unz_file_info64_s
1129573673dSchristos {
1139573673dSchristos     uLong version;              /* version made by                 2 bytes */
1149573673dSchristos     uLong version_needed;       /* version needed to extract       2 bytes */
1159573673dSchristos     uLong flag;                 /* general purpose bit flag        2 bytes */
1169573673dSchristos     uLong compression_method;   /* compression method              2 bytes */
1179573673dSchristos     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
1189573673dSchristos     uLong crc;                  /* crc-32                          4 bytes */
1199573673dSchristos     ZPOS64_T compressed_size;   /* compressed size                 8 bytes */
1209573673dSchristos     ZPOS64_T uncompressed_size; /* uncompressed size               8 bytes */
1219573673dSchristos     uLong size_filename;        /* filename length                 2 bytes */
1229573673dSchristos     uLong size_file_extra;      /* extra field length              2 bytes */
1239573673dSchristos     uLong size_file_comment;    /* file comment length             2 bytes */
1249573673dSchristos 
1259573673dSchristos     uLong disk_num_start;       /* disk number start               2 bytes */
1269573673dSchristos     uLong internal_fa;          /* internal file attributes        2 bytes */
1279573673dSchristos     uLong external_fa;          /* external file attributes        4 bytes */
1289573673dSchristos 
1299573673dSchristos     tm_unz tmu_date;
1309573673dSchristos } unz_file_info64;
1319573673dSchristos 
1329573673dSchristos typedef struct unz_file_info_s
1339573673dSchristos {
1349573673dSchristos     uLong version;              /* version made by                 2 bytes */
1359573673dSchristos     uLong version_needed;       /* version needed to extract       2 bytes */
1369573673dSchristos     uLong flag;                 /* general purpose bit flag        2 bytes */
1379573673dSchristos     uLong compression_method;   /* compression method              2 bytes */
1389573673dSchristos     uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
1399573673dSchristos     uLong crc;                  /* crc-32                          4 bytes */
1409573673dSchristos     uLong compressed_size;      /* compressed size                 4 bytes */
1419573673dSchristos     uLong uncompressed_size;    /* uncompressed size               4 bytes */
1429573673dSchristos     uLong size_filename;        /* filename length                 2 bytes */
1439573673dSchristos     uLong size_file_extra;      /* extra field length              2 bytes */
1449573673dSchristos     uLong size_file_comment;    /* file comment length             2 bytes */
1459573673dSchristos 
1469573673dSchristos     uLong disk_num_start;       /* disk number start               2 bytes */
1479573673dSchristos     uLong internal_fa;          /* internal file attributes        2 bytes */
1489573673dSchristos     uLong external_fa;          /* external file attributes        4 bytes */
1499573673dSchristos 
1509573673dSchristos     tm_unz tmu_date;
1519573673dSchristos } unz_file_info;
1529573673dSchristos 
1539573673dSchristos extern int ZEXPORT unzStringFileNameCompare OF ((const char* fileName1,
1549573673dSchristos                                                  const char* fileName2,
1559573673dSchristos                                                  int iCaseSensitivity));
1569573673dSchristos /*
1579573673dSchristos    Compare two filename (fileName1,fileName2).
1589573673dSchristos    If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
1599573673dSchristos    If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
1609573673dSchristos                                 or strcasecmp)
1619573673dSchristos    If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
1629573673dSchristos     (like 1 on Unix, 2 on Windows)
1639573673dSchristos */
1649573673dSchristos 
1659573673dSchristos 
1669573673dSchristos extern unzFile ZEXPORT unzOpen OF((const char *path));
1679573673dSchristos extern unzFile ZEXPORT unzOpen64 OF((const void *path));
1689573673dSchristos /*
1699573673dSchristos   Open a Zip file. path contain the full pathname (by example,
1709573673dSchristos      on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
1719573673dSchristos      "zlib/zlib113.zip".
1729573673dSchristos      If the zipfile cannot be opened (file don't exist or in not valid), the
1739573673dSchristos        return value is NULL.
1749573673dSchristos      Else, the return value is a unzFile Handle, usable with other function
1759573673dSchristos        of this unzip package.
1769573673dSchristos      the "64" function take a const void* pointer, because the path is just the
1779573673dSchristos        value passed to the open64_file_func callback.
1789573673dSchristos      Under Windows, if UNICODE is defined, using fill_fopen64_filefunc, the path
1799573673dSchristos        is a pointer to a wide unicode string (LPCTSTR is LPCWSTR), so const char*
1809573673dSchristos        does not describe the reality
1819573673dSchristos */
1829573673dSchristos 
1839573673dSchristos 
1849573673dSchristos extern unzFile ZEXPORT unzOpen2 OF((const char *path,
1859573673dSchristos                                     zlib_filefunc_def* pzlib_filefunc_def));
1869573673dSchristos /*
1879573673dSchristos    Open a Zip file, like unzOpen, but provide a set of file low level API
1889573673dSchristos       for read/write the zip file (see ioapi.h)
1899573673dSchristos */
1909573673dSchristos 
1919573673dSchristos extern unzFile ZEXPORT unzOpen2_64 OF((const void *path,
1929573673dSchristos                                     zlib_filefunc64_def* pzlib_filefunc_def));
1939573673dSchristos /*
1949573673dSchristos    Open a Zip file, like unz64Open, but provide a set of file low level API
1959573673dSchristos       for read/write the zip file (see ioapi.h)
1969573673dSchristos */
1979573673dSchristos 
1989573673dSchristos extern int ZEXPORT unzClose OF((unzFile file));
1999573673dSchristos /*
2008cbf5cb7Schristos   Close a ZipFile opened with unzOpen.
2019573673dSchristos   If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
2028cbf5cb7Schristos     these files MUST be closed with unzCloseCurrentFile before call unzClose.
2039573673dSchristos   return UNZ_OK if there is no problem. */
2049573673dSchristos 
2059573673dSchristos extern int ZEXPORT unzGetGlobalInfo OF((unzFile file,
2069573673dSchristos                                         unz_global_info *pglobal_info));
2079573673dSchristos 
2089573673dSchristos extern int ZEXPORT unzGetGlobalInfo64 OF((unzFile file,
2099573673dSchristos                                         unz_global_info64 *pglobal_info));
2109573673dSchristos /*
2119573673dSchristos   Write info about the ZipFile in the *pglobal_info structure.
2129573673dSchristos   No preparation of the structure is needed
2139573673dSchristos   return UNZ_OK if there is no problem. */
2149573673dSchristos 
2159573673dSchristos 
2169573673dSchristos extern int ZEXPORT unzGetGlobalComment OF((unzFile file,
2179573673dSchristos                                            char *szComment,
2189573673dSchristos                                            uLong uSizeBuf));
2199573673dSchristos /*
2209573673dSchristos   Get the global comment string of the ZipFile, in the szComment buffer.
2219573673dSchristos   uSizeBuf is the size of the szComment buffer.
2229573673dSchristos   return the number of byte copied or an error code <0
2239573673dSchristos */
2249573673dSchristos 
2259573673dSchristos 
2269573673dSchristos /***************************************************************************/
2279573673dSchristos /* Unzip package allow you browse the directory of the zipfile */
2289573673dSchristos 
2299573673dSchristos extern int ZEXPORT unzGoToFirstFile OF((unzFile file));
2309573673dSchristos /*
2319573673dSchristos   Set the current file of the zipfile to the first file.
2329573673dSchristos   return UNZ_OK if there is no problem
2339573673dSchristos */
2349573673dSchristos 
2359573673dSchristos extern int ZEXPORT unzGoToNextFile OF((unzFile file));
2369573673dSchristos /*
2379573673dSchristos   Set the current file of the zipfile to the next file.
2389573673dSchristos   return UNZ_OK if there is no problem
2399573673dSchristos   return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
2409573673dSchristos */
2419573673dSchristos 
2429573673dSchristos extern int ZEXPORT unzLocateFile OF((unzFile file,
2439573673dSchristos                      const char *szFileName,
2449573673dSchristos                      int iCaseSensitivity));
2459573673dSchristos /*
2469573673dSchristos   Try locate the file szFileName in the zipfile.
2479573673dSchristos   For the iCaseSensitivity signification, see unzStringFileNameCompare
2489573673dSchristos 
2499573673dSchristos   return value :
2509573673dSchristos   UNZ_OK if the file is found. It becomes the current file.
2519573673dSchristos   UNZ_END_OF_LIST_OF_FILE if the file is not found
2529573673dSchristos */
2539573673dSchristos 
2549573673dSchristos 
2559573673dSchristos /* ****************************************** */
2569573673dSchristos /* Ryan supplied functions */
2579573673dSchristos /* unz_file_info contain information about a file in the zipfile */
2589573673dSchristos typedef struct unz_file_pos_s
2599573673dSchristos {
2609573673dSchristos     uLong pos_in_zip_directory;   /* offset in zip file directory */
2619573673dSchristos     uLong num_of_file;            /* # of file */
2629573673dSchristos } unz_file_pos;
2639573673dSchristos 
2649573673dSchristos extern int ZEXPORT unzGetFilePos(
2659573673dSchristos     unzFile file,
2669573673dSchristos     unz_file_pos* file_pos);
2679573673dSchristos 
2689573673dSchristos extern int ZEXPORT unzGoToFilePos(
2699573673dSchristos     unzFile file,
2709573673dSchristos     unz_file_pos* file_pos);
2719573673dSchristos 
2729573673dSchristos typedef struct unz64_file_pos_s
2739573673dSchristos {
2749573673dSchristos     ZPOS64_T pos_in_zip_directory;   /* offset in zip file directory */
2759573673dSchristos     ZPOS64_T num_of_file;            /* # of file */
2769573673dSchristos } unz64_file_pos;
2779573673dSchristos 
2789573673dSchristos extern int ZEXPORT unzGetFilePos64(
2799573673dSchristos     unzFile file,
2809573673dSchristos     unz64_file_pos* file_pos);
2819573673dSchristos 
2829573673dSchristos extern int ZEXPORT unzGoToFilePos64(
2839573673dSchristos     unzFile file,
2849573673dSchristos     const unz64_file_pos* file_pos);
2859573673dSchristos 
2869573673dSchristos /* ****************************************** */
2879573673dSchristos 
2889573673dSchristos extern int ZEXPORT unzGetCurrentFileInfo64 OF((unzFile file,
2899573673dSchristos                          unz_file_info64 *pfile_info,
2909573673dSchristos                          char *szFileName,
2919573673dSchristos                          uLong fileNameBufferSize,
2929573673dSchristos                          void *extraField,
2939573673dSchristos                          uLong extraFieldBufferSize,
2949573673dSchristos                          char *szComment,
2959573673dSchristos                          uLong commentBufferSize));
2969573673dSchristos 
2979573673dSchristos extern int ZEXPORT unzGetCurrentFileInfo OF((unzFile file,
2989573673dSchristos                          unz_file_info *pfile_info,
2999573673dSchristos                          char *szFileName,
3009573673dSchristos                          uLong fileNameBufferSize,
3019573673dSchristos                          void *extraField,
3029573673dSchristos                          uLong extraFieldBufferSize,
3039573673dSchristos                          char *szComment,
3049573673dSchristos                          uLong commentBufferSize));
3059573673dSchristos /*
3069573673dSchristos   Get Info about the current file
3079573673dSchristos   if pfile_info!=NULL, the *pfile_info structure will contain somes info about
3089573673dSchristos         the current file
3099573673dSchristos   if szFileName!=NULL, the filemane string will be copied in szFileName
3109573673dSchristos             (fileNameBufferSize is the size of the buffer)
3119573673dSchristos   if extraField!=NULL, the extra field information will be copied in extraField
3129573673dSchristos             (extraFieldBufferSize is the size of the buffer).
3139573673dSchristos             This is the Central-header version of the extra field
3149573673dSchristos   if szComment!=NULL, the comment string of the file will be copied in szComment
3159573673dSchristos             (commentBufferSize is the size of the buffer)
3169573673dSchristos */
3179573673dSchristos 
3189573673dSchristos 
3199573673dSchristos /** Addition for GDAL : START */
3209573673dSchristos 
3219573673dSchristos extern ZPOS64_T ZEXPORT unzGetCurrentFileZStreamPos64 OF((unzFile file));
3229573673dSchristos 
3239573673dSchristos /** Addition for GDAL : END */
3249573673dSchristos 
3259573673dSchristos 
3269573673dSchristos /***************************************************************************/
3279573673dSchristos /* for reading the content of the current zipfile, you can open it, read data
3289573673dSchristos    from it, and close it (you can close it before reading all the file)
3299573673dSchristos    */
3309573673dSchristos 
3319573673dSchristos extern int ZEXPORT unzOpenCurrentFile OF((unzFile file));
3329573673dSchristos /*
3339573673dSchristos   Open for reading data the current file in the zipfile.
3349573673dSchristos   If there is no error, the return value is UNZ_OK.
3359573673dSchristos */
3369573673dSchristos 
3379573673dSchristos extern int ZEXPORT unzOpenCurrentFilePassword OF((unzFile file,
3389573673dSchristos                                                   const char* password));
3399573673dSchristos /*
3409573673dSchristos   Open for reading data the current file in the zipfile.
3419573673dSchristos   password is a crypting password
3429573673dSchristos   If there is no error, the return value is UNZ_OK.
3439573673dSchristos */
3449573673dSchristos 
3459573673dSchristos extern int ZEXPORT unzOpenCurrentFile2 OF((unzFile file,
3469573673dSchristos                                            int* method,
3479573673dSchristos                                            int* level,
3489573673dSchristos                                            int raw));
3499573673dSchristos /*
3509573673dSchristos   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
3519573673dSchristos     if raw==1
3529573673dSchristos   *method will receive method of compression, *level will receive level of
3539573673dSchristos      compression
3549573673dSchristos   note : you can set level parameter as NULL (if you did not want known level,
3559573673dSchristos          but you CANNOT set method parameter as NULL
3569573673dSchristos */
3579573673dSchristos 
3589573673dSchristos extern int ZEXPORT unzOpenCurrentFile3 OF((unzFile file,
3599573673dSchristos                                            int* method,
3609573673dSchristos                                            int* level,
3619573673dSchristos                                            int raw,
3629573673dSchristos                                            const char* password));
3639573673dSchristos /*
3649573673dSchristos   Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
3659573673dSchristos     if raw==1
3669573673dSchristos   *method will receive method of compression, *level will receive level of
3679573673dSchristos      compression
3689573673dSchristos   note : you can set level parameter as NULL (if you did not want known level,
3699573673dSchristos          but you CANNOT set method parameter as NULL
3709573673dSchristos */
3719573673dSchristos 
3729573673dSchristos 
3739573673dSchristos extern int ZEXPORT unzCloseCurrentFile OF((unzFile file));
3749573673dSchristos /*
3759573673dSchristos   Close the file in zip opened with unzOpenCurrentFile
3769573673dSchristos   Return UNZ_CRCERROR if all the file was read but the CRC is not good
3779573673dSchristos */
3789573673dSchristos 
3799573673dSchristos extern int ZEXPORT unzReadCurrentFile OF((unzFile file,
3809573673dSchristos                       voidp buf,
3819573673dSchristos                       unsigned len));
3829573673dSchristos /*
3839573673dSchristos   Read bytes from the current file (opened by unzOpenCurrentFile)
3849573673dSchristos   buf contain buffer where data must be copied
3859573673dSchristos   len the size of buf.
3869573673dSchristos 
3879573673dSchristos   return the number of byte copied if somes bytes are copied
3889573673dSchristos   return 0 if the end of file was reached
3899573673dSchristos   return <0 with error code if there is an error
3909573673dSchristos     (UNZ_ERRNO for IO error, or zLib error for uncompress error)
3919573673dSchristos */
3929573673dSchristos 
3939573673dSchristos extern z_off_t ZEXPORT unztell OF((unzFile file));
3949573673dSchristos 
3959573673dSchristos extern ZPOS64_T ZEXPORT unztell64 OF((unzFile file));
3969573673dSchristos /*
3979573673dSchristos   Give the current position in uncompressed data
3989573673dSchristos */
3999573673dSchristos 
4009573673dSchristos extern int ZEXPORT unzeof OF((unzFile file));
4019573673dSchristos /*
4029573673dSchristos   return 1 if the end of file was reached, 0 elsewhere
4039573673dSchristos */
4049573673dSchristos 
4059573673dSchristos extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file,
4069573673dSchristos                                              voidp buf,
4079573673dSchristos                                              unsigned len));
4089573673dSchristos /*
4099573673dSchristos   Read extra field from the current file (opened by unzOpenCurrentFile)
4109573673dSchristos   This is the local-header version of the extra field (sometimes, there is
4119573673dSchristos     more info in the local-header version than in the central-header)
4129573673dSchristos 
4139573673dSchristos   if buf==NULL, it return the size of the local extra field
4149573673dSchristos 
4159573673dSchristos   if buf!=NULL, len is the size of the buffer, the extra header is copied in
4169573673dSchristos     buf.
4179573673dSchristos   the return value is the number of bytes copied in buf, or (if <0)
4189573673dSchristos     the error code
4199573673dSchristos */
4209573673dSchristos 
4219573673dSchristos /***************************************************************************/
4229573673dSchristos 
4239573673dSchristos /* Get the current file offset */
4249573673dSchristos extern ZPOS64_T ZEXPORT unzGetOffset64 (unzFile file);
4259573673dSchristos extern uLong ZEXPORT unzGetOffset (unzFile file);
4269573673dSchristos 
4279573673dSchristos /* Set the current file offset */
4289573673dSchristos extern int ZEXPORT unzSetOffset64 (unzFile file, ZPOS64_T pos);
4299573673dSchristos extern int ZEXPORT unzSetOffset (unzFile file, uLong pos);
4309573673dSchristos 
4319573673dSchristos 
4329573673dSchristos 
4339573673dSchristos #ifdef __cplusplus
4349573673dSchristos }
4359573673dSchristos #endif
4369573673dSchristos 
4379573673dSchristos #endif /* _unz64_H */
438