Mercurial > hg > orthanc
comparison Resources/ThirdParty/minizip/zip.c @ 3284:e583bbf6ec6c
upgraded minizip
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Thu, 21 Feb 2019 18:04:10 +0100 |
parents | 8811abd6aec9 |
children | 44e2a8e0b6ae |
comparison
equal
deleted
inserted
replaced
3283:997db5b2ad50 | 3284:e583bbf6ec6c |
---|---|
13 Oct-2009 - Mathias Svensson - Remove old C style function prototypes | 13 Oct-2009 - Mathias Svensson - Remove old C style function prototypes |
14 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives | 14 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives |
15 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. | 15 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions. |
16 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data | 16 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data |
17 It is used when recreting zip archive with RAW when deleting items from a zip. | 17 It is used when recreting zip archive with RAW when deleting items from a zip. |
18 ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed. | 18 ZIP64 data is automatically added to items that needs it, and existing ZIP64 data need to be removed. |
19 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) | 19 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required) |
20 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer | 20 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer |
21 | 21 |
22 */ | 22 */ |
23 | 23 |
114 typedef struct linkedlist_datablock_internal_s | 114 typedef struct linkedlist_datablock_internal_s |
115 { | 115 { |
116 struct linkedlist_datablock_internal_s* next_datablock; | 116 struct linkedlist_datablock_internal_s* next_datablock; |
117 uLong avail_in_this_block; | 117 uLong avail_in_this_block; |
118 uLong filled_in_this_block; | 118 uLong filled_in_this_block; |
119 uLong unused; /* for future use and alignement */ | 119 uLong unused; /* for future use and alignment */ |
120 unsigned char data[SIZEDATA_INDATABLOCK]; | 120 unsigned char data[SIZEDATA_INDATABLOCK]; |
121 } linkedlist_datablock_internal; | 121 } linkedlist_datablock_internal; |
122 | 122 |
123 typedef struct linkedlist_data_s | 123 typedef struct linkedlist_data_s |
124 { | 124 { |
155 ZPOS64_T pos_zip64extrainfo; | 155 ZPOS64_T pos_zip64extrainfo; |
156 ZPOS64_T totalCompressedData; | 156 ZPOS64_T totalCompressedData; |
157 ZPOS64_T totalUncompressedData; | 157 ZPOS64_T totalUncompressedData; |
158 #ifndef NOCRYPT | 158 #ifndef NOCRYPT |
159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ | 159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */ |
160 const unsigned long* pcrc_32_tab; | 160 const z_crc_t* pcrc_32_tab; |
161 int crypt_header_size; | 161 int crypt_header_size; |
162 #endif | 162 #endif |
163 } curfile64_info; | 163 } curfile64_info; |
164 | 164 |
165 typedef struct | 165 typedef struct |
169 linkedlist_data central_dir;/* datablock with central dir in construction*/ | 169 linkedlist_data central_dir;/* datablock with central dir in construction*/ |
170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ | 170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/ |
171 curfile64_info ci; /* info on the file curretly writing */ | 171 curfile64_info ci; /* info on the file curretly writing */ |
172 | 172 |
173 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ | 173 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */ |
174 ZPOS64_T add_position_when_writting_offset; | 174 ZPOS64_T add_position_when_writing_offset; |
175 ZPOS64_T number_entry; | 175 ZPOS64_T number_entry; |
176 | 176 |
177 #ifndef NO_ADDFILEINEXISTINGZIP | 177 #ifndef NO_ADDFILEINEXISTINGZIP |
178 char *globalcomment; | 178 char *globalcomment; |
179 #endif | 179 #endif |
805 pziinit->globalcomment[size_comment]=0; | 805 pziinit->globalcomment[size_comment]=0; |
806 } | 806 } |
807 } | 807 } |
808 | 808 |
809 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); | 809 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir); |
810 pziinit->add_position_when_writting_offset = byte_before_the_zipfile; | 810 pziinit->add_position_when_writing_offset = byte_before_the_zipfile; |
811 | 811 |
812 { | 812 { |
813 ZPOS64_T size_central_dir_to_read = size_central_dir; | 813 ZPOS64_T size_central_dir_to_read = size_central_dir; |
814 size_t buf_size = SIZEDATA_INDATABLOCK; | 814 size_t buf_size = SIZEDATA_INDATABLOCK; |
815 void* buf_read = (void*)ALLOC(buf_size); | 815 void* buf_read = (void*)ALLOC(buf_size); |
873 | 873 |
874 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); | 874 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream); |
875 ziinit.in_opened_file_inzip = 0; | 875 ziinit.in_opened_file_inzip = 0; |
876 ziinit.ci.stream_initialised = 0; | 876 ziinit.ci.stream_initialised = 0; |
877 ziinit.number_entry = 0; | 877 ziinit.number_entry = 0; |
878 ziinit.add_position_when_writting_offset = 0; | 878 ziinit.add_position_when_writing_offset = 0; |
879 init_linkedlist(&(ziinit.central_dir)); | 879 init_linkedlist(&(ziinit.central_dir)); |
880 | 880 |
881 | 881 |
882 | 882 |
883 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); | 883 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal)); |
1162 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); | 1162 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4); |
1163 | 1163 |
1164 if(zi->ci.pos_local_header >= 0xffffffff) | 1164 if(zi->ci.pos_local_header >= 0xffffffff) |
1165 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); | 1165 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4); |
1166 else | 1166 else |
1167 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4); | 1167 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writing_offset,4); |
1168 | 1168 |
1169 for (i=0;i<size_filename;i++) | 1169 for (i=0;i<size_filename;i++) |
1170 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); | 1170 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i); |
1171 | 1171 |
1172 for (i=0;i<size_extrafield_global;i++) | 1172 for (i=0;i<size_extrafield_global;i++) |
1753 } | 1753 } |
1754 | 1754 |
1755 int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) | 1755 int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip) |
1756 { | 1756 { |
1757 int err = ZIP_OK; | 1757 int err = ZIP_OK; |
1758 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset; | 1758 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writing_offset; |
1759 | 1759 |
1760 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); | 1760 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4); |
1761 | 1761 |
1762 /*num disks*/ | 1762 /*num disks*/ |
1763 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ | 1763 if (err==ZIP_OK) /* number of the disk with the start of the central directory */ |
1806 if (err==ZIP_OK) /* size of the central directory */ | 1806 if (err==ZIP_OK) /* size of the central directory */ |
1807 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); | 1807 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8); |
1808 | 1808 |
1809 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ | 1809 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ |
1810 { | 1810 { |
1811 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | 1811 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; |
1812 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); | 1812 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8); |
1813 } | 1813 } |
1814 return err; | 1814 return err; |
1815 } | 1815 } |
1816 int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) | 1816 int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip) |
1847 if (err==ZIP_OK) /* size of the central directory */ | 1847 if (err==ZIP_OK) /* size of the central directory */ |
1848 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); | 1848 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4); |
1849 | 1849 |
1850 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ | 1850 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */ |
1851 { | 1851 { |
1852 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | 1852 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; |
1853 if(pos >= 0xffffffff) | 1853 if(pos >= 0xffffffff) |
1854 { | 1854 { |
1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); | 1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4); |
1856 } | 1856 } |
1857 else | 1857 else |
1858 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4); | 1858 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writing_offset),4); |
1859 } | 1859 } |
1860 | 1860 |
1861 return err; | 1861 return err; |
1862 } | 1862 } |
1863 | 1863 |
1919 ldi = ldi->next_datablock; | 1919 ldi = ldi->next_datablock; |
1920 } | 1920 } |
1921 } | 1921 } |
1922 free_linkedlist(&(zi->central_dir)); | 1922 free_linkedlist(&(zi->central_dir)); |
1923 | 1923 |
1924 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset; | 1924 pos = centraldir_pos_inzip - zi->add_position_when_writing_offset; |
1925 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) | 1925 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF) |
1926 { | 1926 { |
1927 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); | 1927 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream); |
1928 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); | 1928 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip); |
1929 | 1929 |