annotate Resources/minizip/zip.c @ 111:0fc3b69c0357

preparing for release
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 04 Oct 2012 12:45:24 +0200
parents 7593b57dc1bf
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1 /* zip.c -- IO on .zip files using zlib
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2 Version 1.1, February 14h, 2010
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
3 part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html )
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
4
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
5 Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html )
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
6
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
7 Modifications for Zip64 support
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
8 Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com )
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
9
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
10 For more info read MiniZip_info.txt
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
11
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
12 Changes
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
13 Oct-2009 - Mathias Svensson - Remove old C style function prototypes
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
14 Oct-2009 - Mathias Svensson - Added Zip64 Support when creating new file archives
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
15 Oct-2009 - Mathias Svensson - Did some code cleanup and refactoring to get better overview of some functions.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
16 Oct-2009 - Mathias Svensson - Added zipRemoveExtraInfoBlock to strip extra field data from its ZIP64 data
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
17 It is used when recreting zip archive with RAW when deleting items from a zip.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
18 ZIP64 data is automaticly added to items that needs it, and existing ZIP64 data need to be removed.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
19 Oct-2009 - Mathias Svensson - Added support for BZIP2 as compression mode (bzip2 lib is required)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
20 Jan-2010 - back to unzip and minizip 1.0 name scheme, with compatibility layer
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
21
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
22 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
23
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
24
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
25 #include <stdio.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
26 #include <stdlib.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
27 #include <string.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
28 #include <time.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
29 #include "zlib.h"
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
30 #include "zip.h"
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
31
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
32 #ifdef STDC
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
33 # include <stddef.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
34 # include <string.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
35 # include <stdlib.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
36 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
37 #ifdef NO_ERRNO_H
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
38 extern int errno;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
39 #else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
40 # include <errno.h>
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
41 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
42
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
43
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
44 #ifndef local
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
45 # define local static
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
46 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
47 /* compile with -Dlocal if your debugger can't find static symbols */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
48
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
49 #ifndef VERSIONMADEBY
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
50 # define VERSIONMADEBY (0x0) /* platform depedent */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
51 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
52
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
53 #ifndef Z_BUFSIZE
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
54 #define Z_BUFSIZE (64*1024) //(16384)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
55 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
56
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
57 #ifndef Z_MAXFILENAMEINZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
58 #define Z_MAXFILENAMEINZIP (256)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
59 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
60
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
61 #ifndef ALLOC
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
62 # define ALLOC(size) (malloc(size))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
63 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
64 #ifndef TRYFREE
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
65 # define TRYFREE(p) {if (p) free(p);}
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
66 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
67
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
68 /*
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
69 #define SIZECENTRALDIRITEM (0x2e)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
70 #define SIZEZIPLOCALHEADER (0x1e)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
71 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
72
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
73 /* I've found an old Unix (a SunOS 4.1.3_U1) without all SEEK_* defined.... */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
74
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
75
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
76 // NOT sure that this work on ALL platform
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
77 #define MAKEULONG64(a, b) ((ZPOS64_T)(((unsigned long)(a)) | ((ZPOS64_T)((unsigned long)(b))) << 32))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
78
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
79 #ifndef SEEK_CUR
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
80 #define SEEK_CUR 1
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
81 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
82
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
83 #ifndef SEEK_END
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
84 #define SEEK_END 2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
85 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
86
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
87 #ifndef SEEK_SET
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
88 #define SEEK_SET 0
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
89 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
90
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
91 #ifndef DEF_MEM_LEVEL
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
92 #if MAX_MEM_LEVEL >= 8
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
93 # define DEF_MEM_LEVEL 8
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
94 #else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
95 # define DEF_MEM_LEVEL MAX_MEM_LEVEL
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
96 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
97 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
98 const char zip_copyright[] =" zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll";
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
99
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
100
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
101 #define SIZEDATA_INDATABLOCK (4096-(4*4))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
103 #define LOCALHEADERMAGIC (0x04034b50)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
104 #define CENTRALHEADERMAGIC (0x02014b50)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
105 #define ENDHEADERMAGIC (0x06054b50)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
106 #define ZIP64ENDHEADERMAGIC (0x6064b50)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
107 #define ZIP64ENDLOCHEADERMAGIC (0x7064b50)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
108
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
109 #define FLAG_LOCALHEADER_OFFSET (0x06)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
110 #define CRC_LOCALHEADER_OFFSET (0x0e)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
111
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
112 #define SIZECENTRALHEADER (0x2e) /* 46 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
113
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
114 typedef struct linkedlist_datablock_internal_s
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
115 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
116 struct linkedlist_datablock_internal_s* next_datablock;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
117 uLong avail_in_this_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
118 uLong filled_in_this_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
119 uLong unused; /* for future use and alignement */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
120 unsigned char data[SIZEDATA_INDATABLOCK];
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
121 } linkedlist_datablock_internal;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
122
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
123 typedef struct linkedlist_data_s
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
124 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
125 linkedlist_datablock_internal* first_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
126 linkedlist_datablock_internal* last_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
127 } linkedlist_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
128
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
129
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
130 typedef struct
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
131 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
132 z_stream stream; /* zLib stream structure for inflate */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
133 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
134 bz_stream bstream; /* bzLib stream structure for bziped */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
135 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
136
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
137 int stream_initialised; /* 1 is stream is initialised */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
138 uInt pos_in_buffered_data; /* last written byte in buffered_data */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
139
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
140 ZPOS64_T pos_local_header; /* offset of the local header of the file
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
141 currenty writing */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
142 char* central_header; /* central header data for the current file */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
143 uLong size_centralExtra;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
144 uLong size_centralheader; /* size of the central header for cur file */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
145 uLong size_centralExtraFree; /* Extra bytes allocated to the centralheader but that are not used */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
146 uLong flag; /* flag of the file currently writing */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
147
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
148 int method; /* compression method of file currenty wr.*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
149 int raw; /* 1 for directly writing raw data */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
150 Byte buffered_data[Z_BUFSIZE];/* buffer contain compressed data to be writ*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
151 uLong dosDate;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
152 uLong crc32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
153 int encrypt;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
154 int zip64; /* Add ZIP64 extened information in the extra field */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
155 ZPOS64_T pos_zip64extrainfo;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
156 ZPOS64_T totalCompressedData;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
157 ZPOS64_T totalUncompressedData;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
158 #ifndef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
159 unsigned long keys[3]; /* keys defining the pseudo-random sequence */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
160 const unsigned long* pcrc_32_tab;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
161 int crypt_header_size;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
162 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
163 } curfile64_info;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
164
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
165 typedef struct
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
166 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
167 zlib_filefunc64_32_def z_filefunc;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
168 voidpf filestream; /* io structore of the zipfile */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
169 linkedlist_data central_dir;/* datablock with central dir in construction*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
170 int in_opened_file_inzip; /* 1 if a file in the zip is currently writ.*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
171 curfile64_info ci; /* info on the file curretly writing */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
172
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
173 ZPOS64_T begin_pos; /* position of the beginning of the zipfile */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
174 ZPOS64_T add_position_when_writting_offset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
175 ZPOS64_T number_entry;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
176
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
177 #ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
178 char *globalcomment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
179 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
180
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
181 } zip64_internal;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
182
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
183
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
184 #ifndef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
185 #define INCLUDECRYPTINGCODE_IFCRYPTALLOWED
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
186 #include "crypt.h"
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
187 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
188
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
189 local linkedlist_datablock_internal* allocate_new_datablock()
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
190 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
191 linkedlist_datablock_internal* ldi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
192 ldi = (linkedlist_datablock_internal*)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
193 ALLOC(sizeof(linkedlist_datablock_internal));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
194 if (ldi!=NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
195 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
196 ldi->next_datablock = NULL ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
197 ldi->filled_in_this_block = 0 ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
198 ldi->avail_in_this_block = SIZEDATA_INDATABLOCK ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
199 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
200 return ldi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
201 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
202
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
203 local void free_datablock(linkedlist_datablock_internal* ldi)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
204 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
205 while (ldi!=NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
206 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
207 linkedlist_datablock_internal* ldinext = ldi->next_datablock;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
208 TRYFREE(ldi);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
209 ldi = ldinext;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
210 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
211 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
212
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
213 local void init_linkedlist(linkedlist_data* ll)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
214 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
215 ll->first_block = ll->last_block = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
216 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
217
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
218 local void free_linkedlist(linkedlist_data* ll)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
219 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
220 free_datablock(ll->first_block);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
221 ll->first_block = ll->last_block = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
222 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
223
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
224
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
225 local int add_data_in_datablock(linkedlist_data* ll, const void* buf, uLong len)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
226 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
227 linkedlist_datablock_internal* ldi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
228 const unsigned char* from_copy;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
229
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
230 if (ll==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
231 return ZIP_INTERNALERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
232
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
233 if (ll->last_block == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
234 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
235 ll->first_block = ll->last_block = allocate_new_datablock();
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
236 if (ll->first_block == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
237 return ZIP_INTERNALERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
238 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
239
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
240 ldi = ll->last_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
241 from_copy = (unsigned char*)buf;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
242
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
243 while (len>0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
244 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
245 uInt copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
246 uInt i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
247 unsigned char* to_copy;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
248
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
249 if (ldi->avail_in_this_block==0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
250 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
251 ldi->next_datablock = allocate_new_datablock();
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
252 if (ldi->next_datablock == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
253 return ZIP_INTERNALERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
254 ldi = ldi->next_datablock ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
255 ll->last_block = ldi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
256 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
257
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
258 if (ldi->avail_in_this_block < len)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
259 copy_this = (uInt)ldi->avail_in_this_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
260 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
261 copy_this = (uInt)len;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
262
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
263 to_copy = &(ldi->data[ldi->filled_in_this_block]);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
264
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
265 for (i=0;i<copy_this;i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
266 *(to_copy+i)=*(from_copy+i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
267
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
268 ldi->filled_in_this_block += copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
269 ldi->avail_in_this_block -= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
270 from_copy += copy_this ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
271 len -= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
272 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
273 return ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
274 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
275
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
276
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
277
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
278 /****************************************************************************/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
279
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
280 #ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
281 /* ===========================================================================
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
282 Inputs a long in LSB order to the given file
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
283 nbByte == 1, 2 ,4 or 8 (byte, short or long, ZPOS64_T)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
284 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
285
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
286 local int zip64local_putValue OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
287 local int zip64local_putValue (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T x, int nbByte)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
288 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
289 unsigned char buf[8];
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
290 int n;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
291 for (n = 0; n < nbByte; n++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
292 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
293 buf[n] = (unsigned char)(x & 0xff);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
294 x >>= 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
295 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
296 if (x != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
297 { /* data overflow - hack for ZIP64 (X Roche) */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
298 for (n = 0; n < nbByte; n++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
299 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
300 buf[n] = 0xff;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
301 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
302 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
303
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
304 if (ZWRITE64(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
305 return ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
306 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
307 return ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
308 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
309
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
310 local void zip64local_putValue_inmemory OF((void* dest, ZPOS64_T x, int nbByte));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
311 local void zip64local_putValue_inmemory (void* dest, ZPOS64_T x, int nbByte)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
312 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
313 unsigned char* buf=(unsigned char*)dest;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
314 int n;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
315 for (n = 0; n < nbByte; n++) {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
316 buf[n] = (unsigned char)(x & 0xff);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
317 x >>= 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
318 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
319
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
320 if (x != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
321 { /* data overflow - hack for ZIP64 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
322 for (n = 0; n < nbByte; n++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
323 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
324 buf[n] = 0xff;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
325 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
326 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
327 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
328
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
329 /****************************************************************************/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
330
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
331
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
332 local uLong zip64local_TmzDateToDosDate(const tm_zip* ptm)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
333 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
334 uLong year = (uLong)ptm->tm_year;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
335 if (year>=1980)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
336 year-=1980;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
337 else if (year>=80)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
338 year-=80;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
339 return
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
340 (uLong) (((ptm->tm_mday) + (32 * (ptm->tm_mon+1)) + (512 * year)) << 16) |
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
341 ((ptm->tm_sec/2) + (32* ptm->tm_min) + (2048 * (uLong)ptm->tm_hour));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
342 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
343
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
344
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
345 /****************************************************************************/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
346
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
347 local int zip64local_getByte OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, int *pi));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
348
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
349 local int zip64local_getByte(const zlib_filefunc64_32_def* pzlib_filefunc_def,voidpf filestream,int* pi)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
350 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
351 unsigned char c;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
352 int err = (int)ZREAD64(*pzlib_filefunc_def,filestream,&c,1);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
353 if (err==1)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
354 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
355 *pi = (int)c;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
356 return ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
357 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
358 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
359 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
360 if (ZERROR64(*pzlib_filefunc_def,filestream))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
361 return ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
362 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
363 return ZIP_EOF;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
364 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
365 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
366
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
367
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
368 /* ===========================================================================
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
369 Reads a long in LSB order from the given gz_stream. Sets
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
370 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
371 local int zip64local_getShort OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
372
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
373 local int zip64local_getShort (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
374 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
375 uLong x ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
376 int i = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
377 int err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
378
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
379 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
380 x = (uLong)i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
381
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
382 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
383 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
384 x += ((uLong)i)<<8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
385
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
386 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
387 *pX = x;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
388 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
389 *pX = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
390 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
391 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
392
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
393 local int zip64local_getLong OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong *pX));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
394
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
395 local int zip64local_getLong (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, uLong* pX)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
396 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
397 uLong x ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
398 int i = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
399 int err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
400
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
401 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
402 x = (uLong)i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
403
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
404 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
405 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
406 x += ((uLong)i)<<8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
407
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
408 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
409 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
410 x += ((uLong)i)<<16;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
411
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
412 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
413 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
414 x += ((uLong)i)<<24;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
415
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
416 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
417 *pX = x;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
418 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
419 *pX = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
420 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
421 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
422
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
423 local int zip64local_getLong64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
424
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
425
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
426 local int zip64local_getLong64 (const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream, ZPOS64_T *pX)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
427 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
428 ZPOS64_T x;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
429 int i = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
430 int err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
431
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
432 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
433 x = (ZPOS64_T)i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
434
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
435 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
436 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
437 x += ((ZPOS64_T)i)<<8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
438
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
439 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
440 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
441 x += ((ZPOS64_T)i)<<16;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
442
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
443 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
444 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
445 x += ((ZPOS64_T)i)<<24;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
446
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
447 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
448 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
449 x += ((ZPOS64_T)i)<<32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
450
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
451 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
452 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
453 x += ((ZPOS64_T)i)<<40;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
454
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
455 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
456 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
457 x += ((ZPOS64_T)i)<<48;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
458
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
459 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
460 err = zip64local_getByte(pzlib_filefunc_def,filestream,&i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
461 x += ((ZPOS64_T)i)<<56;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
462
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
463 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
464 *pX = x;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
465 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
466 *pX = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
467
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
468 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
469 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
470
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
471 #ifndef BUFREADCOMMENT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
472 #define BUFREADCOMMENT (0x400)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
473 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
474 /*
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
475 Locate the Central directory of a zipfile (at the end, just before
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
476 the global comment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
477 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
478 local ZPOS64_T zip64local_SearchCentralDir OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
479
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
480 local ZPOS64_T zip64local_SearchCentralDir(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
481 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
482 unsigned char* buf;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
483 ZPOS64_T uSizeFile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
484 ZPOS64_T uBackRead;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
485 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
486 ZPOS64_T uPosFound=0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
487
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
488 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
489 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
490
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
491
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
492 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
493
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
494 if (uMaxBack>uSizeFile)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
495 uMaxBack = uSizeFile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
496
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
497 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
498 if (buf==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
499 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
500
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
501 uBackRead = 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
502 while (uBackRead<uMaxBack)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
503 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
504 uLong uReadSize;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
505 ZPOS64_T uReadPos ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
506 int i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
507 if (uBackRead+BUFREADCOMMENT>uMaxBack)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
508 uBackRead = uMaxBack;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
509 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
510 uBackRead+=BUFREADCOMMENT;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
511 uReadPos = uSizeFile-uBackRead ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
512
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
513 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
514 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
515 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
516 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
517
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
518 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
519 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
520
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
521 for (i=(int)uReadSize-3; (i--)>0;)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
522 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) &&
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
523 ((*(buf+i+2))==0x05) && ((*(buf+i+3))==0x06))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
524 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
525 uPosFound = uReadPos+i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
526 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
527 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
528
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
529 if (uPosFound!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
530 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
531 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
532 TRYFREE(buf);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
533 return uPosFound;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
534 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
535
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
536 /*
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
537 Locate the End of Zip64 Central directory locator and from there find the CD of a zipfile (at the end, just before
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
538 the global comment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
539 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
540 local ZPOS64_T zip64local_SearchCentralDir64 OF((const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
541
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
542 local ZPOS64_T zip64local_SearchCentralDir64(const zlib_filefunc64_32_def* pzlib_filefunc_def, voidpf filestream)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
543 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
544 unsigned char* buf;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
545 ZPOS64_T uSizeFile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
546 ZPOS64_T uBackRead;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
547 ZPOS64_T uMaxBack=0xffff; /* maximum size of global comment */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
548 ZPOS64_T uPosFound=0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
549 uLong uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
550 ZPOS64_T relativeOffset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
551
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
552 if (ZSEEK64(*pzlib_filefunc_def,filestream,0,ZLIB_FILEFUNC_SEEK_END) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
553 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
554
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
555 uSizeFile = ZTELL64(*pzlib_filefunc_def,filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
556
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
557 if (uMaxBack>uSizeFile)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
558 uMaxBack = uSizeFile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
559
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
560 buf = (unsigned char*)ALLOC(BUFREADCOMMENT+4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
561 if (buf==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
562 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
563
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
564 uBackRead = 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
565 while (uBackRead<uMaxBack)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
566 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
567 uLong uReadSize;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
568 ZPOS64_T uReadPos;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
569 int i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
570 if (uBackRead+BUFREADCOMMENT>uMaxBack)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
571 uBackRead = uMaxBack;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
572 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
573 uBackRead+=BUFREADCOMMENT;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
574 uReadPos = uSizeFile-uBackRead ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
575
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
576 uReadSize = ((BUFREADCOMMENT+4) < (uSizeFile-uReadPos)) ?
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
577 (BUFREADCOMMENT+4) : (uLong)(uSizeFile-uReadPos);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
578 if (ZSEEK64(*pzlib_filefunc_def,filestream,uReadPos,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
579 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
580
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
581 if (ZREAD64(*pzlib_filefunc_def,filestream,buf,uReadSize)!=uReadSize)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
582 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
583
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
584 for (i=(int)uReadSize-3; (i--)>0;)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
585 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
586 // Signature "0x07064b50" Zip64 end of central directory locater
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
587 if (((*(buf+i))==0x50) && ((*(buf+i+1))==0x4b) && ((*(buf+i+2))==0x06) && ((*(buf+i+3))==0x07))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
588 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
589 uPosFound = uReadPos+i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
590 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
591 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
592 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
593
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
594 if (uPosFound!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
595 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
596 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
597
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
598 TRYFREE(buf);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
599 if (uPosFound == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
600 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
601
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
602 /* Zip64 end of central directory locator */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
603 if (ZSEEK64(*pzlib_filefunc_def,filestream, uPosFound,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
604 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
605
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
606 /* the signature, already checked */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
607 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
608 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
609
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
610 /* number of the disk with the start of the zip64 end of central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
611 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
612 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
613 if (uL != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
614 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
615
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
616 /* relative offset of the zip64 end of central directory record */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
617 if (zip64local_getLong64(pzlib_filefunc_def,filestream,&relativeOffset)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
618 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
619
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
620 /* total number of disks */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
621 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
622 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
623 if (uL != 1)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
624 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
625
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
626 /* Goto Zip64 end of central directory record */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
627 if (ZSEEK64(*pzlib_filefunc_def,filestream, relativeOffset,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
628 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
629
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
630 /* the signature */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
631 if (zip64local_getLong(pzlib_filefunc_def,filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
632 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
633
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
634 if (uL != 0x06064b50) // signature of 'Zip64 end of central directory'
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
635 return 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
636
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
637 return relativeOffset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
638 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
639
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
640 int LoadCentralDirectoryRecord(zip64_internal* pziinit)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
641 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
642 int err=ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
643 ZPOS64_T byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
644
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
645 ZPOS64_T size_central_dir; /* size of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
646 ZPOS64_T offset_central_dir; /* offset of start of central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
647 ZPOS64_T central_pos;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
648 uLong uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
649
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
650 uLong number_disk; /* number of the current dist, used for
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
651 spaning ZIP, unsupported, always 0*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
652 uLong number_disk_with_CD; /* number the the disk with central dir, used
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
653 for spaning ZIP, unsupported, always 0*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
654 ZPOS64_T number_entry;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
655 ZPOS64_T number_entry_CD; /* total number of entries in
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
656 the central dir
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
657 (same than number_entry on nospan) */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
658 uLong VersionMadeBy;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
659 uLong VersionNeeded;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
660 uLong size_comment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
661
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
662 int hasZIP64Record = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
663
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
664 // check first if we find a ZIP64 record
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
665 central_pos = zip64local_SearchCentralDir64(&pziinit->z_filefunc,pziinit->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
666 if(central_pos > 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
667 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
668 hasZIP64Record = 1;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
669 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
670 else if(central_pos == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
671 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
672 central_pos = zip64local_SearchCentralDir(&pziinit->z_filefunc,pziinit->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
673 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
674
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
675 /* disable to allow appending to empty ZIP archive
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
676 if (central_pos==0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
677 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
678 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
679
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
680 if(hasZIP64Record)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
681 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
682 ZPOS64_T sizeEndOfCentralDirectory;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
683 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos, ZLIB_FILEFUNC_SEEK_SET) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
684 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
685
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
686 /* the signature, already checked */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
687 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
688 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
689
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
690 /* size of zip64 end of central directory record */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
691 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &sizeEndOfCentralDirectory)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
692 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
693
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
694 /* version made by */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
695 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionMadeBy)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
696 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
697
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
698 /* version needed to extract */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
699 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &VersionNeeded)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
700 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
701
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
702 /* number of this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
703 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
704 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
705
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
706 /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
707 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
708 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
709
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
710 /* total number of entries in the central directory on this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
711 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream, &number_entry)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
712 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
713
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
714 /* total number of entries in the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
715 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&number_entry_CD)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
716 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
717
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
718 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
719 err=ZIP_BADZIPFILE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
720
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
721 /* size of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
722 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&size_central_dir)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
723 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
724
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
725 /* offset of start of central directory with respect to the
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
726 starting disk number */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
727 if (zip64local_getLong64(&pziinit->z_filefunc, pziinit->filestream,&offset_central_dir)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
728 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
729
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
730 // TODO..
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
731 // read the comment from the standard central header.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
732 size_comment = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
733 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
734 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
735 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
736 // Read End of central Directory info
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
737 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, central_pos,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
738 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
739
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
740 /* the signature, already checked */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
741 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream,&uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
742 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
743
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
744 /* number of this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
745 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
746 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
747
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
748 /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
749 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream,&number_disk_with_CD)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
750 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
751
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
752 /* total number of entries in the central dir on this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
753 number_entry = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
754 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
755 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
756 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
757 number_entry = uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
758
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
759 /* total number of entries in the central dir */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
760 number_entry_CD = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
761 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
762 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
763 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
764 number_entry_CD = uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
765
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
766 if ((number_entry_CD!=number_entry) || (number_disk_with_CD!=0) || (number_disk!=0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
767 err=ZIP_BADZIPFILE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
768
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
769 /* size of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
770 size_central_dir = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
771 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
772 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
773 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
774 size_central_dir = uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
775
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
776 /* offset of start of central directory with respect to the starting disk number */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
777 offset_central_dir = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
778 if (zip64local_getLong(&pziinit->z_filefunc, pziinit->filestream, &uL)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
779 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
780 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
781 offset_central_dir = uL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
782
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
783
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
784 /* zipfile global comment length */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
785 if (zip64local_getShort(&pziinit->z_filefunc, pziinit->filestream, &size_comment)!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
786 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
787 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
788
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
789 if ((central_pos<offset_central_dir+size_central_dir) &&
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
790 (err==ZIP_OK))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
791 err=ZIP_BADZIPFILE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
792
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
793 if (err!=ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
794 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
795 ZCLOSE64(pziinit->z_filefunc, pziinit->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
796 return ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
797 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
798
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
799 if (size_comment>0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
800 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
801 pziinit->globalcomment = (char*)ALLOC(size_comment+1);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
802 if (pziinit->globalcomment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
803 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
804 size_comment = ZREAD64(pziinit->z_filefunc, pziinit->filestream, pziinit->globalcomment,size_comment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
805 pziinit->globalcomment[size_comment]=0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
806 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
807 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
808
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
809 byte_before_the_zipfile = central_pos - (offset_central_dir+size_central_dir);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
810 pziinit->add_position_when_writting_offset = byte_before_the_zipfile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
811
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
812 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
813 ZPOS64_T size_central_dir_to_read = size_central_dir;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
814 size_t buf_size = SIZEDATA_INDATABLOCK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
815 void* buf_read = (void*)ALLOC(buf_size);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
816 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir + byte_before_the_zipfile, ZLIB_FILEFUNC_SEEK_SET) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
817 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
818
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
819 while ((size_central_dir_to_read>0) && (err==ZIP_OK))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
820 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
821 ZPOS64_T read_this = SIZEDATA_INDATABLOCK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
822 if (read_this > size_central_dir_to_read)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
823 read_this = size_central_dir_to_read;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
824
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
825 if (ZREAD64(pziinit->z_filefunc, pziinit->filestream,buf_read,(uLong)read_this) != read_this)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
826 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
827
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
828 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
829 err = add_data_in_datablock(&pziinit->central_dir,buf_read, (uLong)read_this);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
830
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
831 size_central_dir_to_read-=read_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
832 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
833 TRYFREE(buf_read);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
834 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
835 pziinit->begin_pos = byte_before_the_zipfile;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
836 pziinit->number_entry = number_entry_CD;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
837
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
838 if (ZSEEK64(pziinit->z_filefunc, pziinit->filestream, offset_central_dir+byte_before_the_zipfile,ZLIB_FILEFUNC_SEEK_SET) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
839 err=ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
840
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
841 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
842 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
843
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
844
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
845 #endif /* !NO_ADDFILEINEXISTINGZIP*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
846
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
847
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
848 /************************************************************/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
849 extern zipFile ZEXPORT zipOpen3 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_32_def* pzlib_filefunc64_32_def)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
850 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
851 zip64_internal ziinit;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
852 zip64_internal* zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
853 int err=ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
854
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
855 ziinit.z_filefunc.zseek32_file = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
856 ziinit.z_filefunc.ztell32_file = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
857 if (pzlib_filefunc64_32_def==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
858 fill_fopen64_filefunc(&ziinit.z_filefunc.zfile_func64);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
859 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
860 ziinit.z_filefunc = *pzlib_filefunc64_32_def;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
861
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
862 ziinit.filestream = ZOPEN64(ziinit.z_filefunc,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
863 pathname,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
864 (append == APPEND_STATUS_CREATE) ?
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
865 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_CREATE) :
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
866 (ZLIB_FILEFUNC_MODE_READ | ZLIB_FILEFUNC_MODE_WRITE | ZLIB_FILEFUNC_MODE_EXISTING));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
867
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
868 if (ziinit.filestream == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
869 return NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
870
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
871 if (append == APPEND_STATUS_CREATEAFTER)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
872 ZSEEK64(ziinit.z_filefunc,ziinit.filestream,0,SEEK_END);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
873
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
874 ziinit.begin_pos = ZTELL64(ziinit.z_filefunc,ziinit.filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
875 ziinit.in_opened_file_inzip = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
876 ziinit.ci.stream_initialised = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
877 ziinit.number_entry = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
878 ziinit.add_position_when_writting_offset = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
879 init_linkedlist(&(ziinit.central_dir));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
880
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
881
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
882
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
883 zi = (zip64_internal*)ALLOC(sizeof(zip64_internal));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
884 if (zi==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
885 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
886 ZCLOSE64(ziinit.z_filefunc,ziinit.filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
887 return NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
888 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
889
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
890 /* now we add file in a zipfile */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
891 # ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
892 ziinit.globalcomment = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
893 if (append == APPEND_STATUS_ADDINZIP)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
894 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
895 // Read and Cache Central Directory Records
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
896 err = LoadCentralDirectoryRecord(&ziinit);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
897 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
898
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
899 if (globalcomment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
900 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
901 *globalcomment = ziinit.globalcomment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
902 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
903 # endif /* !NO_ADDFILEINEXISTINGZIP*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
904
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
905 if (err != ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
906 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
907 # ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
908 TRYFREE(ziinit.globalcomment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
909 # endif /* !NO_ADDFILEINEXISTINGZIP*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
910 TRYFREE(zi);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
911 return NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
912 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
913 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
914 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
915 *zi = ziinit;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
916 return (zipFile)zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
917 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
918 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
919
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
920 extern zipFile ZEXPORT zipOpen2 (const char *pathname, int append, zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc32_def)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
921 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
922 if (pzlib_filefunc32_def != NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
923 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
924 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
925 fill_zlib_filefunc64_32_def_from_filefunc32(&zlib_filefunc64_32_def_fill,pzlib_filefunc32_def);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
926 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
927 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
928 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
929 return zipOpen3(pathname, append, globalcomment, NULL);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
930 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
931
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
932 extern zipFile ZEXPORT zipOpen2_64 (const void *pathname, int append, zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
933 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
934 if (pzlib_filefunc_def != NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
935 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
936 zlib_filefunc64_32_def zlib_filefunc64_32_def_fill;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
937 zlib_filefunc64_32_def_fill.zfile_func64 = *pzlib_filefunc_def;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
938 zlib_filefunc64_32_def_fill.ztell32_file = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
939 zlib_filefunc64_32_def_fill.zseek32_file = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
940 return zipOpen3(pathname, append, globalcomment, &zlib_filefunc64_32_def_fill);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
941 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
942 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
943 return zipOpen3(pathname, append, globalcomment, NULL);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
944 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
945
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
946
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
947
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
948 extern zipFile ZEXPORT zipOpen (const char* pathname, int append)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
949 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
950 return zipOpen3((const void*)pathname,append,NULL,NULL);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
951 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
952
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
953 extern zipFile ZEXPORT zipOpen64 (const void* pathname, int append)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
954 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
955 return zipOpen3(pathname,append,NULL,NULL);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
956 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
957
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
958 int Write_LocalFileHeader(zip64_internal* zi, const char* filename, uInt size_extrafield_local, const void* extrafield_local)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
959 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
960 /* write the local header */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
961 int err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
962 uInt size_filename = (uInt)strlen(filename);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
963 uInt size_extrafield = size_extrafield_local;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
964
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
965 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)LOCALHEADERMAGIC, 4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
966
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
967 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
968 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
969 if(zi->ci.zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
970 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);/* version needed to extract */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
971 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
972 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)20,2);/* version needed to extract */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
973 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
974
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
975 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
976 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.flag,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
977
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
978 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
979 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.method,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
980
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
981 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
982 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->ci.dosDate,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
983
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
984 // CRC / Compressed size / Uncompressed size will be filled in later and rewritten later
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
985 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
986 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* crc 32, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
987 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
988 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
989 if(zi->ci.zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
990 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* compressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
991 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
992 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* compressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
993 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
994 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
995 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
996 if(zi->ci.zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
997 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xFFFFFFFF,4); /* uncompressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
998 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
999 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4); /* uncompressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1000 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1001
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1002 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1003 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_filename,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1004
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1005 if(zi->ci.zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1006 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1007 size_extrafield += 20;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1008 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1009
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1010 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1011 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_extrafield,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1012
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1013 if ((err==ZIP_OK) && (size_filename > 0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1014 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1015 if (ZWRITE64(zi->z_filefunc,zi->filestream,filename,size_filename)!=size_filename)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1016 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1017 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1018
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1019 if ((err==ZIP_OK) && (size_extrafield_local > 0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1020 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1021 if (ZWRITE64(zi->z_filefunc, zi->filestream, extrafield_local, size_extrafield_local) != size_extrafield_local)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1022 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1023 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1024
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1025
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1026 if ((err==ZIP_OK) && (zi->ci.zip64))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1027 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1028 // write the Zip64 extended info
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1029 short HeaderID = 1;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1030 short DataSize = 16;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1031 ZPOS64_T CompressedSize = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1032 ZPOS64_T UncompressedSize = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1033
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1034 // Remember position of Zip64 extended info for the local file header. (needed when we update size after done with file)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1035 zi->ci.pos_zip64extrainfo = ZTELL64(zi->z_filefunc,zi->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1036
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1037 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)HeaderID,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1038 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (short)DataSize,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1039
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1040 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)UncompressedSize,8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1041 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, (ZPOS64_T)CompressedSize,8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1042 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1043
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1044 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1045 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1046
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1047 /*
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1048 NOTE.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1049 When writing RAW the ZIP64 extended information in extrafield_local and extrafield_global needs to be stripped
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1050 before calling this function it can be done with zipRemoveExtraInfoBlock
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1051
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1052 It is not done here because then we need to realloc a new buffer since parameters are 'const' and I want to minimize
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1053 unnecessary allocations.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1054 */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1055 extern int ZEXPORT zipOpenNewFileInZip4_64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1056 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1057 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1058 const char* comment, int method, int level, int raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1059 int windowBits,int memLevel, int strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1060 const char* password, uLong crcForCrypting,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1061 uLong versionMadeBy, uLong flagBase, int zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1062 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1063 zip64_internal* zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1064 uInt size_filename;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1065 uInt size_comment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1066 uInt i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1067 int err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1068
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1069 # ifdef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1070 (crcForCrypting);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1071 if (password != NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1072 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1073 # endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1074
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1075 if (file == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1076 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1077
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1078 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1079 if ((method!=0) && (method!=Z_DEFLATED) && (method!=Z_BZIP2ED))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1080 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1081 #else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1082 if ((method!=0) && (method!=Z_DEFLATED))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1083 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1084 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1085
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1086 zi = (zip64_internal*)file;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1087
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1088 if (zi->in_opened_file_inzip == 1)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1089 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1090 err = zipCloseFileInZip (file);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1091 if (err != ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1092 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1093 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1094
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1095 if (filename==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1096 filename="-";
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1097
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1098 if (comment==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1099 size_comment = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1100 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1101 size_comment = (uInt)strlen(comment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1102
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1103 size_filename = (uInt)strlen(filename);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1104
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1105 if (zipfi == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1106 zi->ci.dosDate = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1107 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1108 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1109 if (zipfi->dosDate != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1110 zi->ci.dosDate = zipfi->dosDate;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1111 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1112 zi->ci.dosDate = zip64local_TmzDateToDosDate(&zipfi->tmz_date);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1113 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1114
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1115 zi->ci.flag = flagBase;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1116 if ((level==8) || (level==9))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1117 zi->ci.flag |= 2;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1118 if (level==2)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1119 zi->ci.flag |= 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1120 if (level==1)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1121 zi->ci.flag |= 6;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1122 if (password != NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1123 zi->ci.flag |= 1;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1124
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1125 zi->ci.crc32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1126 zi->ci.method = method;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1127 zi->ci.encrypt = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1128 zi->ci.stream_initialised = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1129 zi->ci.pos_in_buffered_data = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1130 zi->ci.raw = raw;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1131 zi->ci.pos_local_header = ZTELL64(zi->z_filefunc,zi->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1132
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1133 zi->ci.size_centralheader = SIZECENTRALHEADER + size_filename + size_extrafield_global + size_comment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1134 zi->ci.size_centralExtraFree = 32; // Extra space we have reserved in case we need to add ZIP64 extra info data
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1135
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1136 zi->ci.central_header = (char*)ALLOC((uInt)zi->ci.size_centralheader + zi->ci.size_centralExtraFree);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1137
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1138 zi->ci.size_centralExtra = size_extrafield_global;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1139 zip64local_putValue_inmemory(zi->ci.central_header,(uLong)CENTRALHEADERMAGIC,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1140 /* version info */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1141 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)versionMadeBy,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1142 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)20,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1143 zip64local_putValue_inmemory(zi->ci.central_header+8,(uLong)zi->ci.flag,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1144 zip64local_putValue_inmemory(zi->ci.central_header+10,(uLong)zi->ci.method,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1145 zip64local_putValue_inmemory(zi->ci.central_header+12,(uLong)zi->ci.dosDate,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1146 zip64local_putValue_inmemory(zi->ci.central_header+16,(uLong)0,4); /*crc*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1147 zip64local_putValue_inmemory(zi->ci.central_header+20,(uLong)0,4); /*compr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1148 zip64local_putValue_inmemory(zi->ci.central_header+24,(uLong)0,4); /*uncompr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1149 zip64local_putValue_inmemory(zi->ci.central_header+28,(uLong)size_filename,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1150 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)size_extrafield_global,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1151 zip64local_putValue_inmemory(zi->ci.central_header+32,(uLong)size_comment,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1152 zip64local_putValue_inmemory(zi->ci.central_header+34,(uLong)0,2); /*disk nm start*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1153
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1154 if (zipfi==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1155 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)0,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1156 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1157 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)zipfi->internal_fa,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1158
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1159 if (zipfi==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1160 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)0,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1161 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1162 zip64local_putValue_inmemory(zi->ci.central_header+38,(uLong)zipfi->external_fa,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1163
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1164 if(zi->ci.pos_local_header >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1165 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)0xffffffff,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1166 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1167 zip64local_putValue_inmemory(zi->ci.central_header+42,(uLong)zi->ci.pos_local_header - zi->add_position_when_writting_offset,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1168
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1169 for (i=0;i<size_filename;i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1170 *(zi->ci.central_header+SIZECENTRALHEADER+i) = *(filename+i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1171
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1172 for (i=0;i<size_extrafield_global;i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1173 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+i) =
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1174 *(((const char*)extrafield_global)+i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1175
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1176 for (i=0;i<size_comment;i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1177 *(zi->ci.central_header+SIZECENTRALHEADER+size_filename+
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1178 size_extrafield_global+i) = *(comment+i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1179 if (zi->ci.central_header == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1180 return ZIP_INTERNALERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1181
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1182 zi->ci.zip64 = zip64;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1183 zi->ci.totalCompressedData = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1184 zi->ci.totalUncompressedData = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1185 zi->ci.pos_zip64extrainfo = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1186
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1187 err = Write_LocalFileHeader(zi, filename, size_extrafield_local, extrafield_local);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1188
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1189 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1190 zi->ci.bstream.avail_in = (uInt)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1191 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1192 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1193 zi->ci.bstream.total_in_hi32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1194 zi->ci.bstream.total_in_lo32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1195 zi->ci.bstream.total_out_hi32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1196 zi->ci.bstream.total_out_lo32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1197 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1198
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1199 zi->ci.stream.avail_in = (uInt)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1200 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1201 zi->ci.stream.next_out = zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1202 zi->ci.stream.total_in = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1203 zi->ci.stream.total_out = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1204 zi->ci.stream.data_type = Z_BINARY;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1205
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1206 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1207 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED || zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1208 #else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1209 if ((err==ZIP_OK) && (zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1210 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1211 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1212 if(zi->ci.method == Z_DEFLATED)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1213 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1214 zi->ci.stream.zalloc = (alloc_func)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1215 zi->ci.stream.zfree = (free_func)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1216 zi->ci.stream.opaque = (voidpf)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1217
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1218 if (windowBits>0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1219 windowBits = -windowBits;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1220
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1221 err = deflateInit2(&zi->ci.stream, level, Z_DEFLATED, windowBits, memLevel, strategy);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1222
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1223 if (err==Z_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1224 zi->ci.stream_initialised = Z_DEFLATED;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1225 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1226 else if(zi->ci.method == Z_BZIP2ED)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1227 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1228 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1229 // Init BZip stuff here
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1230 zi->ci.bstream.bzalloc = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1231 zi->ci.bstream.bzfree = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1232 zi->ci.bstream.opaque = (voidpf)0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1233
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1234 err = BZ2_bzCompressInit(&zi->ci.bstream, level, 0,35);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1235 if(err == BZ_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1236 zi->ci.stream_initialised = Z_BZIP2ED;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1237 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1238 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1239
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1240 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1241
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1242 # ifndef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1243 zi->ci.crypt_header_size = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1244 if ((err==Z_OK) && (password != NULL))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1245 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1246 unsigned char bufHead[RAND_HEAD_LEN];
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1247 unsigned int sizeHead;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1248 zi->ci.encrypt = 1;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1249 zi->ci.pcrc_32_tab = get_crc_table();
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1250 /*init_keys(password,zi->ci.keys,zi->ci.pcrc_32_tab);*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1251
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1252 sizeHead=crypthead(password,bufHead,RAND_HEAD_LEN,zi->ci.keys,zi->ci.pcrc_32_tab,crcForCrypting);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1253 zi->ci.crypt_header_size = sizeHead;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1254
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1255 if (ZWRITE64(zi->z_filefunc,zi->filestream,bufHead,sizeHead) != sizeHead)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1256 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1257 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1258 # endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1259
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1260 if (err==Z_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1261 zi->in_opened_file_inzip = 1;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1262 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1263 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1264
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1265 extern int ZEXPORT zipOpenNewFileInZip4 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1266 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1267 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1268 const char* comment, int method, int level, int raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1269 int windowBits,int memLevel, int strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1270 const char* password, uLong crcForCrypting,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1271 uLong versionMadeBy, uLong flagBase)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1272 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1273 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1274 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1275 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1276 comment, method, level, raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1277 windowBits, memLevel, strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1278 password, crcForCrypting, versionMadeBy, flagBase, 0);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1279 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1280
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1281 extern int ZEXPORT zipOpenNewFileInZip3 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1282 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1283 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1284 const char* comment, int method, int level, int raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1285 int windowBits,int memLevel, int strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1286 const char* password, uLong crcForCrypting)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1287 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1288 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1289 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1290 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1291 comment, method, level, raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1292 windowBits, memLevel, strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1293 password, crcForCrypting, VERSIONMADEBY, 0, 0);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1294 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1295
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1296 extern int ZEXPORT zipOpenNewFileInZip3_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1297 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1298 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1299 const char* comment, int method, int level, int raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1300 int windowBits,int memLevel, int strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1301 const char* password, uLong crcForCrypting, int zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1302 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1303 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1304 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1305 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1306 comment, method, level, raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1307 windowBits, memLevel, strategy,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1308 password, crcForCrypting, VERSIONMADEBY, 0, zip64);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1309 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1310
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1311 extern int ZEXPORT zipOpenNewFileInZip2(zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1312 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1313 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1314 const char* comment, int method, int level, int raw)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1315 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1316 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1317 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1318 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1319 comment, method, level, raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1320 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1321 NULL, 0, VERSIONMADEBY, 0, 0);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1322 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1323
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1324 extern int ZEXPORT zipOpenNewFileInZip2_64(zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1325 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1326 const void* extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1327 const char* comment, int method, int level, int raw, int zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1328 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1329 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1330 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1331 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1332 comment, method, level, raw,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1333 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1334 NULL, 0, VERSIONMADEBY, 0, zip64);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1335 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1336
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1337 extern int ZEXPORT zipOpenNewFileInZip64 (zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1338 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1339 const void*extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1340 const char* comment, int method, int level, int zip64)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1341 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1342 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1343 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1344 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1345 comment, method, level, 0,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1346 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1347 NULL, 0, VERSIONMADEBY, 0, zip64);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1348 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1349
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1350 extern int ZEXPORT zipOpenNewFileInZip (zipFile file, const char* filename, const zip_fileinfo* zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1351 const void* extrafield_local, uInt size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1352 const void*extrafield_global, uInt size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1353 const char* comment, int method, int level)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1354 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1355 return zipOpenNewFileInZip4_64 (file, filename, zipfi,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1356 extrafield_local, size_extrafield_local,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1357 extrafield_global, size_extrafield_global,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1358 comment, method, level, 0,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1359 -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1360 NULL, 0, VERSIONMADEBY, 0, 0);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1361 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1362
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1363 local int zip64FlushWriteBuffer(zip64_internal* zi)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1364 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1365 int err=ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1366
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1367 if (zi->ci.encrypt != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1368 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1369 #ifndef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1370 uInt i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1371 int t;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1372 for (i=0;i<zi->ci.pos_in_buffered_data;i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1373 zi->ci.buffered_data[i] = zencode(zi->ci.keys, zi->ci.pcrc_32_tab, zi->ci.buffered_data[i],t);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1374 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1375 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1376
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1377 if (ZWRITE64(zi->z_filefunc,zi->filestream,zi->ci.buffered_data,zi->ci.pos_in_buffered_data) != zi->ci.pos_in_buffered_data)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1378 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1379
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1380 zi->ci.totalCompressedData += zi->ci.pos_in_buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1381
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1382 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1383 if(zi->ci.method == Z_BZIP2ED)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1384 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1385 zi->ci.totalUncompressedData += zi->ci.bstream.total_in_lo32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1386 zi->ci.bstream.total_in_lo32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1387 zi->ci.bstream.total_in_hi32 = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1388 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1389 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1390 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1391 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1392 zi->ci.totalUncompressedData += zi->ci.stream.total_in;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1393 zi->ci.stream.total_in = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1394 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1395
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1396
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1397 zi->ci.pos_in_buffered_data = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1398
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1399 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1400 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1401
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1402 extern int ZEXPORT zipWriteInFileInZip (zipFile file,const void* buf,unsigned int len)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1403 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1404 zip64_internal* zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1405 int err=ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1406
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1407 if (file == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1408 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1409 zi = (zip64_internal*)file;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1410
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1411 if (zi->in_opened_file_inzip == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1412 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1413
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1414 zi->ci.crc32 = crc32(zi->ci.crc32,buf,(uInt)len);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1415
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1416 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1417 if(zi->ci.method == Z_BZIP2ED && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1418 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1419 zi->ci.bstream.next_in = (void*)buf;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1420 zi->ci.bstream.avail_in = len;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1421 err = BZ_RUN_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1422
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1423 while ((err==BZ_RUN_OK) && (zi->ci.bstream.avail_in>0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1424 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1425 if (zi->ci.bstream.avail_out == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1426 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1427 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1428 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1429 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1430 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1431 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1432
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1433
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1434 if(err != BZ_RUN_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1435 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1436
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1437 if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1438 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1439 uLong uTotalOutBefore_lo = zi->ci.bstream.total_out_lo32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1440 // uLong uTotalOutBefore_hi = zi->ci.bstream.total_out_hi32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1441 err=BZ2_bzCompress(&zi->ci.bstream, BZ_RUN);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1442
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1443 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore_lo) ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1444 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1445 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1446
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1447 if(err == BZ_RUN_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1448 err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1449 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1450 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1451 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1452 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1453 zi->ci.stream.next_in = (Bytef*)buf;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1454 zi->ci.stream.avail_in = len;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1455
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1456 while ((err==ZIP_OK) && (zi->ci.stream.avail_in>0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1457 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1458 if (zi->ci.stream.avail_out == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1459 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1460 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1461 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1462 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1463 zi->ci.stream.next_out = zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1464 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1465
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1466
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1467 if(err != ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1468 break;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1469
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1470 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1471 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1472 uLong uTotalOutBefore = zi->ci.stream.total_out;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1473 err=deflate(&zi->ci.stream, Z_NO_FLUSH);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1474 if(uTotalOutBefore > zi->ci.stream.total_out)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1475 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1476 int bBreak = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1477 bBreak++;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1478 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1479
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1480 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1481 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1482 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1483 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1484 uInt copy_this,i;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1485 if (zi->ci.stream.avail_in < zi->ci.stream.avail_out)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1486 copy_this = zi->ci.stream.avail_in;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1487 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1488 copy_this = zi->ci.stream.avail_out;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1489
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1490 for (i = 0; i < copy_this; i++)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1491 *(((char*)zi->ci.stream.next_out)+i) =
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1492 *(((const char*)zi->ci.stream.next_in)+i);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1493 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1494 zi->ci.stream.avail_in -= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1495 zi->ci.stream.avail_out-= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1496 zi->ci.stream.next_in+= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1497 zi->ci.stream.next_out+= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1498 zi->ci.stream.total_in+= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1499 zi->ci.stream.total_out+= copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1500 zi->ci.pos_in_buffered_data += copy_this;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1501 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1502 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1503 }// while(...)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1504 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1505
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1506 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1507 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1508
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1509 extern int ZEXPORT zipCloseFileInZipRaw (zipFile file, uLong uncompressed_size, uLong crc32)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1510 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1511 return zipCloseFileInZipRaw64 (file, uncompressed_size, crc32);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1512 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1513
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1514 extern int ZEXPORT zipCloseFileInZipRaw64 (zipFile file, ZPOS64_T uncompressed_size, uLong crc32)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1515 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1516 zip64_internal* zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1517 ZPOS64_T compressed_size;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1518 uLong invalidValue = 0xffffffff;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1519 short datasize = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1520 int err=ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1521
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1522 if (file == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1523 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1524 zi = (zip64_internal*)file;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1525
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1526 if (zi->in_opened_file_inzip == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1527 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1528 zi->ci.stream.avail_in = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1529
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1530 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1531 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1532 while (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1533 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1534 uLong uTotalOutBefore;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1535 if (zi->ci.stream.avail_out == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1536 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1537 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1538 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1539 zi->ci.stream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1540 zi->ci.stream.next_out = zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1541 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1542 uTotalOutBefore = zi->ci.stream.total_out;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1543 err=deflate(&zi->ci.stream, Z_FINISH);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1544 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.stream.total_out - uTotalOutBefore) ;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1545 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1546 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1547 else if ((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1548 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1549 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1550 err = BZ_FINISH_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1551 while (err==BZ_FINISH_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1552 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1553 uLong uTotalOutBefore;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1554 if (zi->ci.bstream.avail_out == 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1555 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1556 if (zip64FlushWriteBuffer(zi) == ZIP_ERRNO)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1557 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1558 zi->ci.bstream.avail_out = (uInt)Z_BUFSIZE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1559 zi->ci.bstream.next_out = (char*)zi->ci.buffered_data;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1560 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1561 uTotalOutBefore = zi->ci.bstream.total_out_lo32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1562 err=BZ2_bzCompress(&zi->ci.bstream, BZ_FINISH);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1563 if(err == BZ_STREAM_END)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1564 err = Z_STREAM_END;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1565
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1566 zi->ci.pos_in_buffered_data += (uInt)(zi->ci.bstream.total_out_lo32 - uTotalOutBefore);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1567 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1568
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1569 if(err == BZ_FINISH_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1570 err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1571 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1572 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1573
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1574 if (err==Z_STREAM_END)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1575 err=ZIP_OK; /* this is normal */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1576
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1577 if ((zi->ci.pos_in_buffered_data>0) && (err==ZIP_OK))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1578 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1579 if (zip64FlushWriteBuffer(zi)==ZIP_ERRNO)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1580 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1581 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1582
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1583 if ((zi->ci.method == Z_DEFLATED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1584 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1585 int tmp_err = deflateEnd(&zi->ci.stream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1586 if (err == ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1587 err = tmp_err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1588 zi->ci.stream_initialised = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1589 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1590 #ifdef HAVE_BZIP2
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1591 else if((zi->ci.method == Z_BZIP2ED) && (!zi->ci.raw))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1592 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1593 int tmperr = BZ2_bzCompressEnd(&zi->ci.bstream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1594 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1595 err = tmperr;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1596 zi->ci.stream_initialised = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1597 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1598 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1599
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1600 if (!zi->ci.raw)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1601 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1602 crc32 = (uLong)zi->ci.crc32;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1603 uncompressed_size = zi->ci.totalUncompressedData;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1604 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1605 compressed_size = zi->ci.totalCompressedData;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1606
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1607 # ifndef NOCRYPT
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1608 compressed_size += zi->ci.crypt_header_size;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1609 # endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1610
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1611 // update Current Item crc and sizes,
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1612 if(compressed_size >= 0xffffffff || uncompressed_size >= 0xffffffff || zi->ci.pos_local_header >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1613 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1614 /*version Made by*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1615 zip64local_putValue_inmemory(zi->ci.central_header+4,(uLong)45,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1616 /*version needed*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1617 zip64local_putValue_inmemory(zi->ci.central_header+6,(uLong)45,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1618
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1619 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1620
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1621 zip64local_putValue_inmemory(zi->ci.central_header+16,crc32,4); /*crc*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1622
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1623
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1624 if(compressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1625 zip64local_putValue_inmemory(zi->ci.central_header+20, invalidValue,4); /*compr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1626 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1627 zip64local_putValue_inmemory(zi->ci.central_header+20, compressed_size,4); /*compr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1628
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1629 /// set internal file attributes field
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1630 if (zi->ci.stream.data_type == Z_ASCII)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1631 zip64local_putValue_inmemory(zi->ci.central_header+36,(uLong)Z_ASCII,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1632
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1633 if(uncompressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1634 zip64local_putValue_inmemory(zi->ci.central_header+24, invalidValue,4); /*uncompr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1635 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1636 zip64local_putValue_inmemory(zi->ci.central_header+24, uncompressed_size,4); /*uncompr size*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1637
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1638 // Add ZIP64 extra info field for uncompressed size
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1639 if(uncompressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1640 datasize += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1641
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1642 // Add ZIP64 extra info field for compressed size
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1643 if(compressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1644 datasize += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1645
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1646 // Add ZIP64 extra info field for relative offset to local file header of current file
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1647 if(zi->ci.pos_local_header >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1648 datasize += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1649
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1650 if(datasize > 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1651 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1652 char* p = NULL;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1653
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1654 if((uLong)(datasize + 4) > zi->ci.size_centralExtraFree)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1655 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1656 // we can not write more data to the buffer that we have room for.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1657 return ZIP_BADZIPFILE;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1658 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1659
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1660 p = zi->ci.central_header + zi->ci.size_centralheader;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1661
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1662 // Add Extra Information Header for 'ZIP64 information'
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1663 zip64local_putValue_inmemory(p, 0x0001, 2); // HeaderID
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1664 p += 2;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1665 zip64local_putValue_inmemory(p, datasize, 2); // DataSize
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1666 p += 2;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1667
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1668 if(uncompressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1669 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1670 zip64local_putValue_inmemory(p, uncompressed_size, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1671 p += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1672 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1673
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1674 if(compressed_size >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1675 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1676 zip64local_putValue_inmemory(p, compressed_size, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1677 p += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1678 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1679
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1680 if(zi->ci.pos_local_header >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1681 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1682 zip64local_putValue_inmemory(p, zi->ci.pos_local_header, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1683 p += 8;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1684 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1685
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1686 // Update how much extra free space we got in the memory buffer
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1687 // and increase the centralheader size so the new ZIP64 fields are included
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1688 // ( 4 below is the size of HeaderID and DataSize field )
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1689 zi->ci.size_centralExtraFree -= datasize + 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1690 zi->ci.size_centralheader += datasize + 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1691
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1692 // Update the extra info size field
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1693 zi->ci.size_centralExtra += datasize + 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1694 zip64local_putValue_inmemory(zi->ci.central_header+30,(uLong)zi->ci.size_centralExtra,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1695 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1696
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1697 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1698 err = add_data_in_datablock(&zi->central_dir, zi->ci.central_header, (uLong)zi->ci.size_centralheader);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1699
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1700 free(zi->ci.central_header);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1701
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1702 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1703 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1704 // Update the LocalFileHeader with the new values.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1705
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1706 ZPOS64_T cur_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1707
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1708 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_local_header + 14,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1709 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1710
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1711 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1712 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,crc32,4); /* crc 32, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1713
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1714 if(uncompressed_size >= 0xffffffff || compressed_size >= 0xffffffff )
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1715 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1716 if(zi->ci.pos_zip64extrainfo > 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1717 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1718 // Update the size in the ZIP64 extended field.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1719 if (ZSEEK64(zi->z_filefunc,zi->filestream, zi->ci.pos_zip64extrainfo + 4,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1720 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1721
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1722 if (err==ZIP_OK) /* compressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1723 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, uncompressed_size, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1724
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1725 if (err==ZIP_OK) /* uncompressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1726 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, compressed_size, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1727 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1728 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1729 err = ZIP_BADZIPFILE; // Caller passed zip64 = 0, so no room for zip64 info -> fatal
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1730 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1731 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1732 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1733 if (err==ZIP_OK) /* compressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1734 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,compressed_size,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1735
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1736 if (err==ZIP_OK) /* uncompressed size, unknown */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1737 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,uncompressed_size,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1738 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1739
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1740 if (ZSEEK64(zi->z_filefunc,zi->filestream, cur_pos_inzip,ZLIB_FILEFUNC_SEEK_SET)!=0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1741 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1742 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1743
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1744 zi->number_entry ++;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1745 zi->in_opened_file_inzip = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1746
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1747 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1748 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1749
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1750 extern int ZEXPORT zipCloseFileInZip (zipFile file)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1751 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1752 return zipCloseFileInZipRaw (file,0,0);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1753 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1754
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1755 int Write_Zip64EndOfCentralDirectoryLocator(zip64_internal* zi, ZPOS64_T zip64eocd_pos_inzip)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1756 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1757 int err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1758 ZPOS64_T pos = zip64eocd_pos_inzip - zi->add_position_when_writting_offset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1759
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1760 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDLOCHEADERMAGIC,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1761
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1762 /*num disks*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1763 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1764 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1765
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1766 /*relative offset*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1767 if (err==ZIP_OK) /* Relative offset to the Zip64EndOfCentralDirectory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1768 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, pos,8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1769
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1770 /*total disks*/ /* Do not support spawning of disk so always say 1 here*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1771 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1772 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)1,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1773
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1774 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1775 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1776
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1777 int Write_Zip64EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1778 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1779 int err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1780
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1781 uLong Zip64DataSize = 44;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1782
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1783 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ZIP64ENDHEADERMAGIC,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1784
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1785 if (err==ZIP_OK) /* size of this 'zip64 end of central directory' */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1786 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)Zip64DataSize,8); // why ZPOS64_T of this ?
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1787
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1788 if (err==ZIP_OK) /* version made by */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1789 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1790
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1791 if (err==ZIP_OK) /* version needed */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1792 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)45,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1793
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1794 if (err==ZIP_OK) /* number of this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1795 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1796
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1797 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1798 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1799
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1800 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1801 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1802
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1803 if (err==ZIP_OK) /* total number of entries in the central dir */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1804 err = zip64local_putValue(&zi->z_filefunc, zi->filestream, zi->number_entry, 8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1805
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1806 if (err==ZIP_OK) /* size of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1807 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(ZPOS64_T)size_centraldir,8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1808
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1809 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1810 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1811 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1812 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (ZPOS64_T)pos,8);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1813 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1814 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1815 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1816 int Write_EndOfCentralDirectoryRecord(zip64_internal* zi, uLong size_centraldir, ZPOS64_T centraldir_pos_inzip)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1817 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1818 int err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1819
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1820 /*signature*/
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1821 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)ENDHEADERMAGIC,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1822
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1823 if (err==ZIP_OK) /* number of this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1824 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1825
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1826 if (err==ZIP_OK) /* number of the disk with the start of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1827 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1828
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1829 if (err==ZIP_OK) /* total number of entries in the central dir on this disk */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1830 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1831 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1832 if(zi->number_entry >= 0xFFFF)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1833 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1834 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1835 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1836 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1837 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1838
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1839 if (err==ZIP_OK) /* total number of entries in the central dir */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1840 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1841 if(zi->number_entry >= 0xFFFF)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1842 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)0xffff,2); // use value in ZIP64 record
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1843 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1844 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)zi->number_entry,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1845 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1846
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1847 if (err==ZIP_OK) /* size of the central directory */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1848 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_centraldir,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1849
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1850 if (err==ZIP_OK) /* offset of start of central directory with respect to the starting disk number */
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1851 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1852 ZPOS64_T pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1853 if(pos >= 0xffffffff)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1854 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1855 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)0xffffffff,4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1856 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1857 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1858 err = zip64local_putValue(&zi->z_filefunc,zi->filestream, (uLong)(centraldir_pos_inzip - zi->add_position_when_writting_offset),4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1859 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1860
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1861 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1862 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1863
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1864 int Write_GlobalComment(zip64_internal* zi, const char* global_comment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1865 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1866 int err = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1867 uInt size_global_comment = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1868
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1869 if(global_comment != NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1870 size_global_comment = (uInt)strlen(global_comment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1871
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1872 err = zip64local_putValue(&zi->z_filefunc,zi->filestream,(uLong)size_global_comment,2);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1873
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1874 if (err == ZIP_OK && size_global_comment > 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1875 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1876 if (ZWRITE64(zi->z_filefunc,zi->filestream, global_comment, size_global_comment) != size_global_comment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1877 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1878 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1879 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1880 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1881
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1882 extern int ZEXPORT zipClose (zipFile file, const char* global_comment)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1883 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1884 zip64_internal* zi;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1885 int err = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1886 uLong size_centraldir = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1887 ZPOS64_T centraldir_pos_inzip;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1888 ZPOS64_T pos;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1889
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1890 if (file == NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1891 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1892
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1893 zi = (zip64_internal*)file;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1894
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1895 if (zi->in_opened_file_inzip == 1)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1896 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1897 err = zipCloseFileInZip (file);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1898 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1899
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1900 #ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1901 if (global_comment==NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1902 global_comment = zi->globalcomment;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1903 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1904
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1905 centraldir_pos_inzip = ZTELL64(zi->z_filefunc,zi->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1906
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1907 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1908 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1909 linkedlist_datablock_internal* ldi = zi->central_dir.first_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1910 while (ldi!=NULL)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1911 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1912 if ((err==ZIP_OK) && (ldi->filled_in_this_block>0))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1913 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1914 if (ZWRITE64(zi->z_filefunc,zi->filestream, ldi->data, ldi->filled_in_this_block) != ldi->filled_in_this_block)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1915 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1916 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1917
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1918 size_centraldir += ldi->filled_in_this_block;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1919 ldi = ldi->next_datablock;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1920 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1921 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1922 free_linkedlist(&(zi->central_dir));
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1923
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1924 pos = centraldir_pos_inzip - zi->add_position_when_writting_offset;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1925 if(pos >= 0xffffffff || zi->number_entry > 0xFFFF)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1926 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1927 ZPOS64_T Zip64EOCDpos = ZTELL64(zi->z_filefunc,zi->filestream);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1928 Write_Zip64EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1929
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1930 Write_Zip64EndOfCentralDirectoryLocator(zi, Zip64EOCDpos);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1931 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1932
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1933 if (err==ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1934 err = Write_EndOfCentralDirectoryRecord(zi, size_centraldir, centraldir_pos_inzip);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1935
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1936 if(err == ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1937 err = Write_GlobalComment(zi, global_comment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1938
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1939 if (ZCLOSE64(zi->z_filefunc,zi->filestream) != 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1940 if (err == ZIP_OK)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1941 err = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1942
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1943 #ifndef NO_ADDFILEINEXISTINGZIP
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1944 TRYFREE(zi->globalcomment);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1945 #endif
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1946 TRYFREE(zi);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1947
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1948 return err;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1949 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1950
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1951 extern int ZEXPORT zipRemoveExtraInfoBlock (char* pData, int* dataLen, short sHeader)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1952 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1953 char* p = pData;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1954 int size = 0;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1955 char* pNewHeader;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1956 char* pTmp;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1957 short header;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1958 short dataSize;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1959
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1960 int retVal = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1961
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1962 if(pData == NULL || *dataLen < 4)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1963 return ZIP_PARAMERROR;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1964
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1965 pNewHeader = (char*)ALLOC(*dataLen);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1966 pTmp = pNewHeader;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1967
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1968 while(p < (pData + *dataLen))
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1969 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1970 header = *(short*)p;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1971 dataSize = *(((short*)p)+1);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1972
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1973 if( header == sHeader ) // Header found.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1974 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1975 p += dataSize + 4; // skip it. do not copy to temp buffer
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1976 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1977 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1978 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1979 // Extra Info block should not be removed, So copy it to the temp buffer.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1980 memcpy(pTmp, p, dataSize + 4);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1981 p += dataSize + 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1982 size += dataSize + 4;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1983 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1984
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1985 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1986
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1987 if(size < *dataLen)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1988 {
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1989 // clean old extra info block.
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1990 memset(pData,0, *dataLen);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1991
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1992 // copy the new extra info block over the old
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1993 if(size > 0)
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1994 memcpy(pData, pNewHeader, size);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1995
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1996 // set the new extra info size
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1997 *dataLen = size;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1998
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
1999 retVal = ZIP_OK;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2000 }
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2001 else
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2002 retVal = ZIP_ERRNO;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2003
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2004 TRYFREE(pNewHeader);
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2005
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2006 return retVal;
7593b57dc1bf switch to google log
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
diff changeset
2007 }