diff options
author | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:23:45 -0700 |
---|---|---|
committer | Mark Adler <madler@alumni.caltech.edu> | 2011-09-09 23:23:45 -0700 |
commit | 7a6955760ba950eb82f57929f8f6c9847c65f0af (patch) | |
tree | e2cd657aca6d606e0b28bf57fe45e914717a334c /contrib | |
parent | f0e76a6634eb26e3ddc6dfc6f2489553eff8c8f4 (diff) | |
download | zlib-1.2.1.2.tar.gz zlib-1.2.1.2.tar.bz2 zlib-1.2.1.2.zip |
zlib 1.2.1.2v1.2.1.2
Diffstat (limited to 'contrib')
33 files changed, 965 insertions, 307 deletions
diff --git a/contrib/README.contrib b/contrib/README.contrib index 8860f31..eae15aa 100644 --- a/contrib/README.contrib +++ b/contrib/README.contrib | |||
@@ -67,4 +67,4 @@ visual-basic.txt by Carlos Rios <c_rios@sonda.cl> | |||
67 | How to use compress(), uncompress() and the gz* functions from VB | 67 | How to use compress(), uncompress() and the gz* functions from VB |
68 | 68 | ||
69 | vstudio/ by Gilles Vollant <info@winimage.com> | 69 | vstudio/ by Gilles Vollant <info@winimage.com> |
70 | Building zlib with Visual Studio .NET | 70 | Building a minizip-enhanced zlib with Visual Studio .NET |
diff --git a/contrib/ada/buffer_demo.adb b/contrib/ada/buffer_demo.adb new file mode 100644 index 0000000..46b8638 --- /dev/null +++ b/contrib/ada/buffer_demo.adb | |||
@@ -0,0 +1,106 @@ | |||
1 | ---------------------------------------------------------------- | ||
2 | -- ZLib for Ada thick binding. -- | ||
3 | -- -- | ||
4 | -- Copyright (C) 2002-2004 Dmitriy Anisimkov -- | ||
5 | -- -- | ||
6 | -- Open source license information is in the zlib.ads file. -- | ||
7 | ---------------------------------------------------------------- | ||
8 | -- | ||
9 | -- $Id: buffer_demo.adb,v 1.3 2004/09/06 06:55:35 vagul Exp $ | ||
10 | |||
11 | -- This demo program provided by Dr Steve Sangwine <sjs@essex.ac.uk> | ||
12 | -- | ||
13 | -- Demonstration of a problem with Zlib-Ada (already fixed) when a buffer | ||
14 | -- of exactly the correct size is used for decompressed data, and the last | ||
15 | -- few bytes passed in to Zlib are checksum bytes. | ||
16 | |||
17 | -- This program compresses a string of text, and then decompresses the | ||
18 | -- compressed text into a buffer of the same size as the original text. | ||
19 | |||
20 | with Ada.Streams; use Ada.Streams; | ||
21 | with Ada.Text_IO; | ||
22 | |||
23 | with ZLib; use ZLib; | ||
24 | |||
25 | procedure Buffer_Demo is | ||
26 | EOL : Character renames ASCII.LF; | ||
27 | Text : constant String | ||
28 | := "Four score and seven years ago our fathers brought forth," & EOL & | ||
29 | "upon this continent, a new nation, conceived in liberty," & EOL & | ||
30 | "and dedicated to the proposition that `all men are created equal'."; | ||
31 | |||
32 | Source : Stream_Element_Array (1 .. Text'Length); | ||
33 | for Source'Address use Text'Address; | ||
34 | |||
35 | begin | ||
36 | Ada.Text_IO.Put (Text); | ||
37 | Ada.Text_IO.New_Line; | ||
38 | Ada.Text_IO.Put_Line | ||
39 | ("Uncompressed size : " & Positive'Image (Text'Length) & " bytes"); | ||
40 | |||
41 | declare | ||
42 | Compressed_Data : Stream_Element_Array (1 .. Text'Length); | ||
43 | L : Stream_Element_Offset; | ||
44 | begin | ||
45 | Compress : declare | ||
46 | Compressor : Filter_Type; | ||
47 | I : Stream_Element_Offset; | ||
48 | begin | ||
49 | Deflate_Init (Compressor); | ||
50 | |||
51 | -- Compress the whole of T at once. | ||
52 | |||
53 | Translate (Compressor, Source, I, Compressed_Data, L, Finish); | ||
54 | pragma Assert (I = Source'Last); | ||
55 | |||
56 | Close (Compressor); | ||
57 | |||
58 | Ada.Text_IO.Put_Line | ||
59 | ("Compressed size : " | ||
60 | & Stream_Element_Offset'Image (L) & " bytes"); | ||
61 | end Compress; | ||
62 | |||
63 | -- Now we decompress the data, passing short blocks of data to Zlib | ||
64 | -- (because this demonstrates the problem - the last block passed will | ||
65 | -- contain checksum information and there will be no output, only a | ||
66 | -- check inside Zlib that the checksum is correct). | ||
67 | |||
68 | Decompress : declare | ||
69 | Decompressor : Filter_Type; | ||
70 | |||
71 | Uncompressed_Data : Stream_Element_Array (1 .. Text'Length); | ||
72 | |||
73 | Block_Size : constant := 4; | ||
74 | -- This makes sure that the last block contains | ||
75 | -- only Adler checksum data. | ||
76 | |||
77 | P : Stream_Element_Offset := Compressed_Data'First - 1; | ||
78 | O : Stream_Element_Offset; | ||
79 | begin | ||
80 | Inflate_Init (Decompressor); | ||
81 | |||
82 | loop | ||
83 | Translate | ||
84 | (Decompressor, | ||
85 | Compressed_Data | ||
86 | (P + 1 .. Stream_Element_Offset'Min (P + Block_Size, L)), | ||
87 | P, | ||
88 | Uncompressed_Data | ||
89 | (Total_Out (Decompressor) + 1 .. Uncompressed_Data'Last), | ||
90 | O, | ||
91 | No_Flush); | ||
92 | |||
93 | Ada.Text_IO.Put_Line | ||
94 | ("Total in : " & Count'Image (Total_In (Decompressor)) & | ||
95 | ", out : " & Count'Image (Total_Out (Decompressor))); | ||
96 | |||
97 | exit when P = L; | ||
98 | end loop; | ||
99 | |||
100 | Ada.Text_IO.New_Line; | ||
101 | Ada.Text_IO.Put_Line | ||
102 | ("Decompressed text matches original text : " | ||
103 | & Boolean'Image (Uncompressed_Data = Source)); | ||
104 | end Decompress; | ||
105 | end; | ||
106 | end Buffer_Demo; | ||
diff --git a/contrib/ada/mtest.adb b/contrib/ada/mtest.adb index 91a96cd..c4dfd08 100644 --- a/contrib/ada/mtest.adb +++ b/contrib/ada/mtest.adb | |||
@@ -5,10 +5,10 @@ | |||
5 | -- -- | 5 | -- -- |
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | -- Continuous test for ZLib multithreading. If the test is fail | 8 | -- Continuous test for ZLib multithreading. If the test would fail |
9 | -- Wou should provide thread safe allocation routines for the Z_Stream. | 9 | -- we should provide thread safe allocation routines for the Z_Stream. |
10 | -- | 10 | -- |
11 | -- $Id: mtest.adb,v 1.2 2003/08/12 12:11:05 vagul Exp $ | 11 | -- $Id: mtest.adb,v 1.4 2004/07/23 07:49:54 vagul Exp $ |
12 | 12 | ||
13 | with ZLib; | 13 | with ZLib; |
14 | with Ada.Streams; | 14 | with Ada.Streams; |
@@ -148,6 +148,9 @@ procedure MTest is | |||
148 | 148 | ||
149 | pragma Unreferenced (Test); | 149 | pragma Unreferenced (Test); |
150 | 150 | ||
151 | Dummy : Character; | ||
152 | |||
151 | begin | 153 | begin |
152 | null; | 154 | Ada.Text_IO.Get_Immediate (Dummy); |
155 | Stop := True; | ||
153 | end MTest; | 156 | end MTest; |
diff --git a/contrib/ada/read.adb b/contrib/ada/read.adb index 184ea00..1f2efbf 100644 --- a/contrib/ada/read.adb +++ b/contrib/ada/read.adb | |||
@@ -6,7 +6,7 @@ | |||
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: read.adb,v 1.7 2003/08/12 12:12:35 vagul Exp $ | 9 | -- $Id: read.adb,v 1.8 2004/05/31 10:53:40 vagul Exp $ |
10 | 10 | ||
11 | -- Test/demo program for the generic read interface. | 11 | -- Test/demo program for the generic read interface. |
12 | 12 | ||
@@ -68,7 +68,11 @@ procedure Read is | |||
68 | -- ZLib.Read | 68 | -- ZLib.Read |
69 | -- reading data from the File_In. | 69 | -- reading data from the File_In. |
70 | 70 | ||
71 | procedure Read is new ZLib.Read (Read, Read_Buffer, Read_First, Read_Last); | 71 | procedure Read is new ZLib.Read |
72 | (Read, | ||
73 | Read_Buffer, | ||
74 | Rest_First => Read_First, | ||
75 | Rest_Last => Read_Last); | ||
72 | 76 | ||
73 | ---------- | 77 | ---------- |
74 | -- Read -- | 78 | -- Read -- |
@@ -103,6 +107,7 @@ procedure Read is | |||
103 | Pack_Size := 0; | 107 | Pack_Size := 0; |
104 | Offset := 1; | 108 | Offset := 1; |
105 | Read_First := Read_Buffer'Last + 1; | 109 | Read_First := Read_Buffer'Last + 1; |
110 | Read_Last := Read_Buffer'Last; | ||
106 | end Reset; | 111 | end Reset; |
107 | 112 | ||
108 | begin | 113 | begin |
diff --git a/contrib/ada/readme.txt b/contrib/ada/readme.txt index ad02c22..dec7ef3 100644 --- a/contrib/ada/readme.txt +++ b/contrib/ada/readme.txt | |||
@@ -1,20 +1,31 @@ | |||
1 | |||
2 | ZLib for Ada thick binding (ZLib.Ada) | 1 | ZLib for Ada thick binding (ZLib.Ada) |
3 | Release 1.2 | 2 | Release 1.3 |
4 | 3 | ||
5 | ZLib.Ada is a thick binding interface to the popular ZLib data | 4 | ZLib.Ada is a thick binding interface to the popular ZLib data |
6 | compression library, available at http://www.gzip.org/zlib/. | 5 | compression library, available at http://www.gzip.org/zlib/. |
7 | It provides Ada-style access to the ZLib C library. | 6 | It provides Ada-style access to the ZLib C library. |
8 | 7 | ||
9 | 8 | ||
10 | Here are the main changes since ZLib.Ada 1.1: | 9 | Here are the main changes since ZLib.Ada 1.2: |
10 | |||
11 | - Attension: ZLib.Read generic routine have a initialization requirement | ||
12 | for Read_Last parameter now. It is a bit incompartible with previous version, | ||
13 | but extends functionality, we could use new parameters Allow_Read_Some and | ||
14 | Flush now. | ||
15 | |||
16 | - Added Is_Open routines to ZLib and ZLib.Streams packages. | ||
11 | 17 | ||
12 | - The default header type has a name "Default" now. Auto is used only for | 18 | - Add pragma Assert to check Stream_Element is 8 bit. |
13 | automatic GZip/ZLib header detection. | ||
14 | 19 | ||
15 | - Added test for multitasking mtest.adb. | 20 | - Fix extraction to buffer with exact known decompressed size. Error reported by |
21 | Steve Sangwine. | ||
16 | 22 | ||
17 | - Added GNAT project file zlib.gpr. | 23 | - Fix definition of ULong (changed to unsigned_long), fix regression on 64 bits |
24 | computers. Patch provided by Pascal Obry. | ||
25 | |||
26 | - Add Status_Error exception definition. | ||
27 | |||
28 | - Add pragma Assertion that Ada.Streams.Stream_Element size is 8 bit. | ||
18 | 29 | ||
19 | 30 | ||
20 | How to build ZLib.Ada under GNAT | 31 | How to build ZLib.Ada under GNAT |
@@ -50,3 +61,5 @@ The routines from the package specifications are commented. | |||
50 | 61 | ||
51 | Homepage: http://zlib-ada.sourceforge.net/ | 62 | Homepage: http://zlib-ada.sourceforge.net/ |
52 | Author: Dmitriy Anisimkov <anisimkov@yahoo.com> | 63 | Author: Dmitriy Anisimkov <anisimkov@yahoo.com> |
64 | |||
65 | Contributors: Pascal Obry <pascal@obry.org>, Steve Sangwine <sjs@essex.ac.uk> | ||
diff --git a/contrib/ada/zlib-streams.adb b/contrib/ada/zlib-streams.adb index d213b5c..398664a 100644 --- a/contrib/ada/zlib-streams.adb +++ b/contrib/ada/zlib-streams.adb | |||
@@ -6,7 +6,7 @@ | |||
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: zlib-streams.adb,v 1.9 2003/08/12 13:15:31 vagul Exp $ | 9 | -- $Id: zlib-streams.adb,v 1.10 2004/05/31 10:53:40 vagul Exp $ |
10 | 10 | ||
11 | with Ada.Unchecked_Deallocation; | 11 | with Ada.Unchecked_Deallocation; |
12 | 12 | ||
@@ -90,6 +90,7 @@ package body ZLib.Streams is | |||
90 | 90 | ||
91 | Stream.Buffer := new Buffer_Subtype; | 91 | Stream.Buffer := new Buffer_Subtype; |
92 | Stream.Rest_First := Stream.Buffer'Last + 1; | 92 | Stream.Rest_First := Stream.Buffer'Last + 1; |
93 | Stream.Rest_Last := Stream.Buffer'Last; | ||
93 | end if; | 94 | end if; |
94 | end Create; | 95 | end Create; |
95 | 96 | ||
@@ -113,6 +114,15 @@ package body ZLib.Streams is | |||
113 | end loop; | 114 | end loop; |
114 | end Flush; | 115 | end Flush; |
115 | 116 | ||
117 | ------------- | ||
118 | -- Is_Open -- | ||
119 | ------------- | ||
120 | |||
121 | function Is_Open (Stream : Stream_Type) return Boolean is | ||
122 | begin | ||
123 | return Is_Open (Stream.Reader) or else Is_Open (Stream.Writer); | ||
124 | end Is_Open; | ||
125 | |||
116 | ---------- | 126 | ---------- |
117 | -- Read -- | 127 | -- Read -- |
118 | ---------- | 128 | ---------- |
@@ -212,4 +222,4 @@ package body ZLib.Streams is | |||
212 | return Total_Out (Stream.Writer); | 222 | return Total_Out (Stream.Writer); |
213 | end Write_Total_Out; | 223 | end Write_Total_Out; |
214 | 224 | ||
215 | end ZLib.Streams; | 225 | end ZLib.Streams; \ No newline at end of file |
diff --git a/contrib/ada/zlib-streams.ads b/contrib/ada/zlib-streams.ads index 1d5e904..5c68667 100644 --- a/contrib/ada/zlib-streams.ads +++ b/contrib/ada/zlib-streams.ads | |||
@@ -6,7 +6,7 @@ | |||
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: zlib-streams.ads,v 1.11 2003/08/12 13:15:31 vagul Exp $ | 9 | -- $Id: zlib-streams.ads,v 1.12 2004/05/31 10:53:40 vagul Exp $ |
10 | 10 | ||
11 | package ZLib.Streams is | 11 | package ZLib.Streams is |
12 | 12 | ||
@@ -77,6 +77,8 @@ package ZLib.Streams is | |||
77 | -- !!! When the Need_Header is False ZLib-Ada is using undocumented | 77 | -- !!! When the Need_Header is False ZLib-Ada is using undocumented |
78 | -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. | 78 | -- ZLib 1.1.4 functionality to do not create/wait for ZLib headers. |
79 | 79 | ||
80 | function Is_Open (Stream : Stream_Type) return Boolean; | ||
81 | |||
80 | procedure Close (Stream : in out Stream_Type); | 82 | procedure Close (Stream : in out Stream_Type); |
81 | 83 | ||
82 | private | 84 | private |
@@ -109,4 +111,4 @@ private | |||
109 | Writer : Filter_Type; | 111 | Writer : Filter_Type; |
110 | end record; | 112 | end record; |
111 | 113 | ||
112 | end ZLib.Streams; | 114 | end ZLib.Streams; \ No newline at end of file |
diff --git a/contrib/ada/zlib-thin.adb b/contrib/ada/zlib-thin.adb index 163bd5b..0ca4a71 100644 --- a/contrib/ada/zlib-thin.adb +++ b/contrib/ada/zlib-thin.adb | |||
@@ -6,12 +6,11 @@ | |||
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: zlib-thin.adb,v 1.6 2003/01/21 15:26:37 vagul Exp $ | 9 | -- $Id: zlib-thin.adb,v 1.8 2003/12/14 18:27:31 vagul Exp $ |
10 | 10 | ||
11 | package body ZLib.Thin is | 11 | package body ZLib.Thin is |
12 | 12 | ||
13 | ZLIB_VERSION : constant Chars_Ptr := | 13 | ZLIB_VERSION : constant Chars_Ptr := zlibVersion; |
14 | Interfaces.C.Strings.New_String ("1.1.4"); | ||
15 | 14 | ||
16 | Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; | 15 | Z_Stream_Size : constant Int := Z_Stream'Size / System.Storage_Unit; |
17 | 16 | ||
@@ -38,14 +37,6 @@ package body ZLib.Thin is | |||
38 | ------------------ | 37 | ------------------ |
39 | 38 | ||
40 | function Deflate_Init | 39 | function Deflate_Init |
41 | (strm : in Z_Streamp; | ||
42 | level : in Int := Z_DEFAULT_COMPRESSION) | ||
43 | return Int is | ||
44 | begin | ||
45 | return deflateInit (strm, level, ZLIB_VERSION, Z_Stream_Size); | ||
46 | end Deflate_Init; | ||
47 | |||
48 | function Deflate_Init | ||
49 | (strm : Z_Streamp; | 40 | (strm : Z_Streamp; |
50 | level : Int; | 41 | level : Int; |
51 | method : Int; | 42 | method : Int; |
@@ -69,16 +60,15 @@ package body ZLib.Thin is | |||
69 | -- Inflate_Init -- | 60 | -- Inflate_Init -- |
70 | ------------------ | 61 | ------------------ |
71 | 62 | ||
72 | function Inflate_Init (strm : Z_Streamp) return Int is | ||
73 | begin | ||
74 | return inflateInit (strm, ZLIB_VERSION, Z_Stream_Size); | ||
75 | end Inflate_Init; | ||
76 | |||
77 | function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is | 63 | function Inflate_Init (strm : Z_Streamp; windowBits : Int) return Int is |
78 | begin | 64 | begin |
79 | return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); | 65 | return inflateInit2 (strm, windowBits, ZLIB_VERSION, Z_Stream_Size); |
80 | end Inflate_Init; | 66 | end Inflate_Init; |
81 | 67 | ||
68 | ------------------------ | ||
69 | -- Last_Error_Message -- | ||
70 | ------------------------ | ||
71 | |||
82 | function Last_Error_Message (Strm : in Z_Stream) return String is | 72 | function Last_Error_Message (Strm : in Z_Stream) return String is |
83 | use Interfaces.C.Strings; | 73 | use Interfaces.C.Strings; |
84 | begin | 74 | begin |
@@ -89,54 +79,28 @@ package body ZLib.Thin is | |||
89 | end if; | 79 | end if; |
90 | end Last_Error_Message; | 80 | end Last_Error_Message; |
91 | 81 | ||
92 | ------------- | ||
93 | -- Need_In -- | ||
94 | ------------- | ||
95 | |||
96 | function Need_In (strm : Z_Stream) return Boolean is | ||
97 | begin | ||
98 | return strm.Avail_In = 0; | ||
99 | end Need_In; | ||
100 | |||
101 | -------------- | ||
102 | -- Need_Out -- | ||
103 | -------------- | ||
104 | |||
105 | function Need_Out (strm : Z_Stream) return Boolean is | ||
106 | begin | ||
107 | return strm.Avail_Out = 0; | ||
108 | end Need_Out; | ||
109 | |||
110 | ------------ | 82 | ------------ |
111 | -- Set_In -- | 83 | -- Set_In -- |
112 | ------------ | 84 | ------------ |
113 | 85 | ||
114 | procedure Set_In | 86 | procedure Set_In |
115 | (Strm : in out Z_Stream; | 87 | (Strm : in out Z_Stream; |
116 | Buffer : in Byte_Access; | 88 | Buffer : in Voidp; |
117 | Size : in UInt) is | 89 | Size : in UInt) is |
118 | begin | 90 | begin |
119 | Strm.Next_In := Buffer; | 91 | Strm.Next_In := Buffer; |
120 | Strm.Avail_In := Size; | 92 | Strm.Avail_In := Size; |
121 | end Set_In; | 93 | end Set_In; |
122 | 94 | ||
123 | procedure Set_In | ||
124 | (Strm : in out Z_Stream; | ||
125 | Buffer : in Voidp; | ||
126 | Size : in UInt) is | ||
127 | begin | ||
128 | Set_In (Strm, Bytes.To_Pointer (Buffer), Size); | ||
129 | end Set_In; | ||
130 | |||
131 | ------------------ | 95 | ------------------ |
132 | -- Set_Mem_Func -- | 96 | -- Set_Mem_Func -- |
133 | ------------------ | 97 | ------------------ |
134 | 98 | ||
135 | procedure Set_Mem_Func | 99 | procedure Set_Mem_Func |
136 | (Strm : in out Z_Stream; | 100 | (Strm : in out Z_Stream; |
137 | Opaque : in Voidp; | 101 | Opaque : in Voidp; |
138 | Alloc : in alloc_func; | 102 | Alloc : in alloc_func; |
139 | Free : in free_func) is | 103 | Free : in free_func) is |
140 | begin | 104 | begin |
141 | Strm.opaque := Opaque; | 105 | Strm.opaque := Opaque; |
142 | Strm.zalloc := Alloc; | 106 | Strm.zalloc := Alloc; |
@@ -149,21 +113,13 @@ package body ZLib.Thin is | |||
149 | 113 | ||
150 | procedure Set_Out | 114 | procedure Set_Out |
151 | (Strm : in out Z_Stream; | 115 | (Strm : in out Z_Stream; |
152 | Buffer : in Byte_Access; | 116 | Buffer : in Voidp; |
153 | Size : in UInt) is | 117 | Size : in UInt) is |
154 | begin | 118 | begin |
155 | Strm.Next_Out := Buffer; | 119 | Strm.Next_Out := Buffer; |
156 | Strm.Avail_Out := Size; | 120 | Strm.Avail_Out := Size; |
157 | end Set_Out; | 121 | end Set_Out; |
158 | 122 | ||
159 | procedure Set_Out | ||
160 | (Strm : in out Z_Stream; | ||
161 | Buffer : in Voidp; | ||
162 | Size : in UInt) is | ||
163 | begin | ||
164 | Set_Out (Strm, Bytes.To_Pointer (Buffer), Size); | ||
165 | end Set_Out; | ||
166 | |||
167 | -------------- | 123 | -------------- |
168 | -- Total_In -- | 124 | -- Total_In -- |
169 | -------------- | 125 | -------------- |
diff --git a/contrib/ada/zlib-thin.ads b/contrib/ada/zlib-thin.ads index c227374..d4407eb 100644 --- a/contrib/ada/zlib-thin.ads +++ b/contrib/ada/zlib-thin.ads | |||
@@ -6,10 +6,11 @@ | |||
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: zlib-thin.ads,v 1.8 2003/08/12 13:16:51 vagul Exp $ | 9 | -- $Id: zlib-thin.ads,v 1.11 2004/07/23 06:33:11 vagul Exp $ |
10 | 10 | ||
11 | with Interfaces.C.Strings; | 11 | with Interfaces.C.Strings; |
12 | with System.Address_To_Access_Conversions; | 12 | |
13 | with System; | ||
13 | 14 | ||
14 | private package ZLib.Thin is | 15 | private package ZLib.Thin is |
15 | 16 | ||
@@ -36,18 +37,18 @@ private package ZLib.Thin is | |||
36 | -- zconf.h:216 | 37 | -- zconf.h:216 |
37 | type Int is new Interfaces.C.int; | 38 | type Int is new Interfaces.C.int; |
38 | 39 | ||
39 | type ULong is new Interfaces.C.unsigned; -- 32 bits or more | 40 | type ULong is new Interfaces.C.unsigned_long; -- 32 bits or more |
40 | -- zconf.h:217 | 41 | -- zconf.h:217 |
41 | subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; | 42 | subtype Chars_Ptr is Interfaces.C.Strings.chars_ptr; |
42 | 43 | ||
43 | type ULong_Access is access ULong; | 44 | type ULong_Access is access ULong; |
44 | type Int_Access is access Int; | 45 | type Int_Access is access Int; |
45 | subtype Voidp is System.Address; -- zconf.h:232 | ||
46 | 46 | ||
47 | package Bytes is new System.Address_To_Access_Conversions (Byte); | 47 | subtype Voidp is System.Address; -- zconf.h:232 |
48 | 48 | ||
49 | subtype Byte_Access is Bytes.Object_Pointer; | 49 | subtype Byte_Access is Voidp; |
50 | 50 | ||
51 | Nul : constant Voidp := System.Null_Address; | ||
51 | -- end from zconf | 52 | -- end from zconf |
52 | 53 | ||
53 | Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 | 54 | Z_NO_FLUSH : constant := 8#0000#; -- zlib.h:125 |
@@ -251,12 +252,6 @@ private package ZLib.Thin is | |||
251 | stream_size : Int) | 252 | stream_size : Int) |
252 | return Int; | 253 | return Int; |
253 | 254 | ||
254 | function Deflate_Init | ||
255 | (strm : in Z_Streamp; | ||
256 | level : in Int := Z_DEFAULT_COMPRESSION) | ||
257 | return Int; | ||
258 | pragma Inline (Deflate_Init); | ||
259 | |||
260 | function deflateInit2 | 255 | function deflateInit2 |
261 | (strm : Z_Streamp; | 256 | (strm : Z_Streamp; |
262 | level : Int; | 257 | level : Int; |
@@ -284,9 +279,6 @@ private package ZLib.Thin is | |||
284 | stream_size : Int) | 279 | stream_size : Int) |
285 | return Int; | 280 | return Int; |
286 | 281 | ||
287 | function Inflate_Init (strm : Z_Streamp) return Int; | ||
288 | pragma Inline (Inflate_Init); | ||
289 | |||
290 | function inflateInit2 | 282 | function inflateInit2 |
291 | (strm : in Z_Streamp; | 283 | (strm : in Z_Streamp; |
292 | windowBits : in Int; | 284 | windowBits : in Int; |
@@ -318,20 +310,6 @@ private package ZLib.Thin is | |||
318 | -- has dropped to zero. The application must initialize zalloc, zfree and | 310 | -- has dropped to zero. The application must initialize zalloc, zfree and |
319 | -- opaque before calling the init function. | 311 | -- opaque before calling the init function. |
320 | 312 | ||
321 | function Need_In (strm : in Z_Stream) return Boolean; | ||
322 | -- return true when we do not need to setup Next_In and Avail_In fields. | ||
323 | pragma Inline (Need_In); | ||
324 | |||
325 | function Need_Out (strm : in Z_Stream) return Boolean; | ||
326 | -- return true when we do not need to setup Next_Out and Avail_Out field. | ||
327 | pragma Inline (Need_Out); | ||
328 | |||
329 | procedure Set_In | ||
330 | (Strm : in out Z_Stream; | ||
331 | Buffer : in Byte_Access; | ||
332 | Size : in UInt); | ||
333 | pragma Inline (Set_In); | ||
334 | |||
335 | procedure Set_In | 313 | procedure Set_In |
336 | (Strm : in out Z_Stream; | 314 | (Strm : in out Z_Stream; |
337 | Buffer : in Voidp; | 315 | Buffer : in Voidp; |
@@ -340,12 +318,6 @@ private package ZLib.Thin is | |||
340 | 318 | ||
341 | procedure Set_Out | 319 | procedure Set_Out |
342 | (Strm : in out Z_Stream; | 320 | (Strm : in out Z_Stream; |
343 | Buffer : in Byte_Access; | ||
344 | Size : in UInt); | ||
345 | pragma Inline (Set_Out); | ||
346 | |||
347 | procedure Set_Out | ||
348 | (Strm : in out Z_Stream; | ||
349 | Buffer : in Voidp; | 321 | Buffer : in Voidp; |
350 | Size : in UInt); | 322 | Size : in UInt); |
351 | pragma Inline (Set_Out); | 323 | pragma Inline (Set_Out); |
@@ -388,19 +360,13 @@ private package ZLib.Thin is | |||
388 | 360 | ||
389 | function zlibCompileFlags return ULong; | 361 | function zlibCompileFlags return ULong; |
390 | 362 | ||
391 | function deflatePrime | ||
392 | (strm : Z_Streamp; | ||
393 | bits : Int; | ||
394 | value : Int) | ||
395 | return Int; | ||
396 | |||
397 | private | 363 | private |
398 | 364 | ||
399 | type Z_Stream is record -- zlib.h:68 | 365 | type Z_Stream is record -- zlib.h:68 |
400 | Next_In : Byte_Access; -- next input byte | 366 | Next_In : Voidp := Nul; -- next input byte |
401 | Avail_In : UInt := 0; -- number of bytes available at next_in | 367 | Avail_In : UInt := 0; -- number of bytes available at next_in |
402 | Total_In : ULong := 0; -- total nb of input bytes read so far | 368 | Total_In : ULong := 0; -- total nb of input bytes read so far |
403 | Next_Out : Byte_Access; -- next output byte should be put there | 369 | Next_Out : Voidp := Nul; -- next output byte should be put there |
404 | Avail_Out : UInt := 0; -- remaining free space at next_out | 370 | Avail_Out : UInt := 0; -- remaining free space at next_out |
405 | Total_Out : ULong := 0; -- total nb of bytes output so far | 371 | Total_Out : ULong := 0; -- total nb of bytes output so far |
406 | msg : Chars_Ptr; -- last error message, NULL if no error | 372 | msg : Chars_Ptr; -- last error message, NULL if no error |
@@ -460,14 +426,13 @@ private | |||
460 | pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); | 426 | pragma Import (C, inflateSyncPoint, "inflateSyncPoint"); |
461 | pragma Import (C, get_crc_table, "get_crc_table"); | 427 | pragma Import (C, get_crc_table, "get_crc_table"); |
462 | 428 | ||
463 | -- added in zlib 1.2.1: | 429 | -- since zlib 1.2.0: |
464 | 430 | ||
465 | pragma Import (C, inflateCopy, "inflateCopy"); | 431 | pragma Import (C, inflateCopy, "inflateCopy"); |
466 | pragma Import (C, compressBound, "compressBound"); | 432 | pragma Import (C, compressBound, "compressBound"); |
467 | pragma Import (C, deflateBound, "deflateBound"); | 433 | pragma Import (C, deflateBound, "deflateBound"); |
468 | pragma Import (C, gzungetc, "gzungetc"); | 434 | pragma Import (C, gzungetc, "gzungetc"); |
469 | pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); | 435 | pragma Import (C, zlibCompileFlags, "zlibCompileFlags"); |
470 | pragma Import (C, deflatePrime, "deflatePrime"); | ||
471 | 436 | ||
472 | pragma Import (C, inflateBackInit, "inflateBackInit_"); | 437 | pragma Import (C, inflateBackInit, "inflateBackInit_"); |
473 | 438 | ||
diff --git a/contrib/ada/zlib.adb b/contrib/ada/zlib.adb index 93bf885..8b6fd68 100644 --- a/contrib/ada/zlib.adb +++ b/contrib/ada/zlib.adb | |||
@@ -1,12 +1,12 @@ | |||
1 | ---------------------------------------------------------------- | 1 | ---------------------------------------------------------------- |
2 | -- ZLib for Ada thick binding. -- | 2 | -- ZLib for Ada thick binding. -- |
3 | -- -- | 3 | -- -- |
4 | -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- | 4 | -- Copyright (C) 2002-2004 Dmitriy Anisimkov -- |
5 | -- -- | 5 | -- -- |
6 | -- Open source license information is in the zlib.ads file. -- | 6 | -- Open source license information is in the zlib.ads file. -- |
7 | ---------------------------------------------------------------- | 7 | ---------------------------------------------------------------- |
8 | 8 | ||
9 | -- $Id: zlib.adb,v 1.19 2003/07/13 16:02:19 vagul Exp $ | 9 | -- $Id: zlib.adb,v 1.31 2004/09/06 06:53:19 vagul Exp $ |
10 | 10 | ||
11 | with Ada.Exceptions; | 11 | with Ada.Exceptions; |
12 | with Ada.Unchecked_Conversion; | 12 | with Ada.Unchecked_Conversion; |
@@ -34,7 +34,7 @@ package body ZLib is | |||
34 | VERSION_ERROR); | 34 | VERSION_ERROR); |
35 | 35 | ||
36 | type Flate_Step_Function is access | 36 | type Flate_Step_Function is access |
37 | function (Strm : Thin.Z_Streamp; flush : Thin.Int) return Thin.Int; | 37 | function (Strm : in Thin.Z_Streamp; Flush : in Thin.Int) return Thin.Int; |
38 | pragma Convention (C, Flate_Step_Function); | 38 | pragma Convention (C, Flate_Step_Function); |
39 | 39 | ||
40 | type Flate_End_Function is access | 40 | type Flate_End_Function is access |
@@ -82,13 +82,13 @@ package body ZLib is | |||
82 | Flush_Finish : constant array (Boolean) of Flush_Mode | 82 | Flush_Finish : constant array (Boolean) of Flush_Mode |
83 | := (True => Finish, False => No_Flush); | 83 | := (True => Finish, False => No_Flush); |
84 | 84 | ||
85 | procedure Raise_Error (Stream : Z_Stream); | 85 | procedure Raise_Error (Stream : in Z_Stream); |
86 | pragma Inline (Raise_Error); | 86 | pragma Inline (Raise_Error); |
87 | 87 | ||
88 | procedure Raise_Error (Message : String); | 88 | procedure Raise_Error (Message : in String); |
89 | pragma Inline (Raise_Error); | 89 | pragma Inline (Raise_Error); |
90 | 90 | ||
91 | procedure Check_Error (Stream : Z_Stream; Code : Thin.Int); | 91 | procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int); |
92 | 92 | ||
93 | procedure Free is new Ada.Unchecked_Deallocation | 93 | procedure Free is new Ada.Unchecked_Deallocation |
94 | (Z_Stream, Z_Stream_Access); | 94 | (Z_Stream, Z_Stream_Access); |
@@ -118,7 +118,7 @@ package body ZLib is | |||
118 | -- Check_Error -- | 118 | -- Check_Error -- |
119 | ----------------- | 119 | ----------------- |
120 | 120 | ||
121 | procedure Check_Error (Stream : Z_Stream; Code : Thin.Int) is | 121 | procedure Check_Error (Stream : in Z_Stream; Code : in Thin.Int) is |
122 | use type Thin.Int; | 122 | use type Thin.Int; |
123 | begin | 123 | begin |
124 | if Code /= Thin.Z_OK then | 124 | if Code /= Thin.Z_OK then |
@@ -138,10 +138,11 @@ package body ZLib is | |||
138 | is | 138 | is |
139 | Code : Thin.Int; | 139 | Code : Thin.Int; |
140 | begin | 140 | begin |
141 | Code := Flate (Filter.Compression).Done | 141 | if not Ignore_Error and then not Is_Open (Filter) then |
142 | (To_Thin_Access (Filter.Strm)); | 142 | raise Status_Error; |
143 | end if; | ||
143 | 144 | ||
144 | Filter.Opened := False; | 145 | Code := Flate (Filter.Compression).Done (To_Thin_Access (Filter.Strm)); |
145 | 146 | ||
146 | if Ignore_Error or else Code = Thin.Z_OK then | 147 | if Ignore_Error or else Code = Thin.Z_OK then |
147 | Free (Filter.Strm); | 148 | Free (Filter.Strm); |
@@ -154,7 +155,7 @@ package body ZLib is | |||
154 | Ada.Exceptions.Raise_Exception | 155 | Ada.Exceptions.Raise_Exception |
155 | (ZLib_Error'Identity, | 156 | (ZLib_Error'Identity, |
156 | Return_Code_Enum'Image (Return_Code (Code)) | 157 | Return_Code_Enum'Image (Return_Code (Code)) |
157 | & ": " & Error_Message); | 158 | & ": " & Error_Message); |
158 | end; | 159 | end; |
159 | end if; | 160 | end if; |
160 | end Close; | 161 | end Close; |
@@ -170,10 +171,9 @@ package body ZLib is | |||
170 | is | 171 | is |
171 | use Thin; | 172 | use Thin; |
172 | begin | 173 | begin |
173 | return Unsigned_32 (crc32 | 174 | return Unsigned_32 (crc32 (ULong (CRC), |
174 | (ULong (CRC), | 175 | Data'Address, |
175 | Bytes.To_Pointer (Data'Address), | 176 | Data'Length)); |
176 | Data'Length)); | ||
177 | end CRC32; | 177 | end CRC32; |
178 | 178 | ||
179 | procedure CRC32 | 179 | procedure CRC32 |
@@ -192,13 +192,17 @@ package body ZLib is | |||
192 | Level : in Compression_Level := Default_Compression; | 192 | Level : in Compression_Level := Default_Compression; |
193 | Strategy : in Strategy_Type := Default_Strategy; | 193 | Strategy : in Strategy_Type := Default_Strategy; |
194 | Method : in Compression_Method := Deflated; | 194 | Method : in Compression_Method := Deflated; |
195 | Window_Bits : in Window_Bits_Type := 15; | 195 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
196 | Memory_Level : in Memory_Level_Type := 8; | 196 | Memory_Level : in Memory_Level_Type := Default_Memory_Level; |
197 | Header : in Header_Type := Default) | 197 | Header : in Header_Type := Default) |
198 | is | 198 | is |
199 | use type Thin.Int; | 199 | use type Thin.Int; |
200 | Win_Bits : Thin.Int := Thin.Int (Window_Bits); | 200 | Win_Bits : Thin.Int := Thin.Int (Window_Bits); |
201 | begin | 201 | begin |
202 | if Is_Open (Filter) then | ||
203 | raise Status_Error; | ||
204 | end if; | ||
205 | |||
202 | -- We allow ZLib to make header only in case of default header type. | 206 | -- We allow ZLib to make header only in case of default header type. |
203 | -- Otherwise we would either do header by ourselfs, or do not do | 207 | -- Otherwise we would either do header by ourselfs, or do not do |
204 | -- header at all. | 208 | -- header at all. |
@@ -216,10 +220,9 @@ package body ZLib is | |||
216 | Filter.Offset := Simple_GZip_Header'Last + 1; | 220 | Filter.Offset := Simple_GZip_Header'Last + 1; |
217 | end if; | 221 | end if; |
218 | 222 | ||
219 | Filter.Strm := new Z_Stream; | 223 | Filter.Strm := new Z_Stream; |
220 | Filter.Compression := True; | 224 | Filter.Compression := True; |
221 | Filter.Stream_End := False; | 225 | Filter.Stream_End := False; |
222 | Filter.Opened := True; | ||
223 | Filter.Header := Header; | 226 | Filter.Header := Header; |
224 | 227 | ||
225 | if Thin.Deflate_Init | 228 | if Thin.Deflate_Init |
@@ -255,18 +258,18 @@ package body ZLib is | |||
255 | ----------------------- | 258 | ----------------------- |
256 | 259 | ||
257 | procedure Generic_Translate | 260 | procedure Generic_Translate |
258 | (Filter : in out ZLib.Filter_Type; | 261 | (Filter : in out ZLib.Filter_Type; |
259 | In_Buffer_Size : Integer := Default_Buffer_Size; | 262 | In_Buffer_Size : in Integer := Default_Buffer_Size; |
260 | Out_Buffer_Size : Integer := Default_Buffer_Size) | 263 | Out_Buffer_Size : in Integer := Default_Buffer_Size) |
261 | is | 264 | is |
262 | In_Buffer : Stream_Element_Array | 265 | In_Buffer : Stream_Element_Array |
263 | (1 .. Stream_Element_Offset (In_Buffer_Size)); | 266 | (1 .. Stream_Element_Offset (In_Buffer_Size)); |
264 | Out_Buffer : Stream_Element_Array | 267 | Out_Buffer : Stream_Element_Array |
265 | (1 .. Stream_Element_Offset (Out_Buffer_Size)); | 268 | (1 .. Stream_Element_Offset (Out_Buffer_Size)); |
266 | Last : Stream_Element_Offset; | 269 | Last : Stream_Element_Offset; |
267 | In_Last : Stream_Element_Offset; | 270 | In_Last : Stream_Element_Offset; |
268 | In_First : Stream_Element_Offset; | 271 | In_First : Stream_Element_Offset; |
269 | Out_Last : Stream_Element_Offset; | 272 | Out_Last : Stream_Element_Offset; |
270 | begin | 273 | begin |
271 | Main : loop | 274 | Main : loop |
272 | Data_In (In_Buffer, Last); | 275 | Data_In (In_Buffer, Last); |
@@ -275,18 +278,21 @@ package body ZLib is | |||
275 | 278 | ||
276 | loop | 279 | loop |
277 | Translate | 280 | Translate |
278 | (Filter, | 281 | (Filter => Filter, |
279 | In_Buffer (In_First .. Last), | 282 | In_Data => In_Buffer (In_First .. Last), |
280 | In_Last, | 283 | In_Last => In_Last, |
281 | Out_Buffer, | 284 | Out_Data => Out_Buffer, |
282 | Out_Last, | 285 | Out_Last => Out_Last, |
283 | Flush_Finish (Last < In_Buffer'First)); | 286 | Flush => Flush_Finish (Last < In_Buffer'First)); |
284 | 287 | ||
285 | Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last)); | 288 | if Out_Buffer'First <= Out_Last then |
289 | Data_Out (Out_Buffer (Out_Buffer'First .. Out_Last)); | ||
290 | end if; | ||
286 | 291 | ||
287 | exit Main when Stream_End (Filter); | 292 | exit Main when Stream_End (Filter); |
288 | 293 | ||
289 | -- The end of in buffer. | 294 | -- The end of in buffer. |
295 | |||
290 | exit when In_Last = Last; | 296 | exit when In_Last = Last; |
291 | 297 | ||
292 | In_First := In_Last + 1; | 298 | In_First := In_Last + 1; |
@@ -301,7 +307,7 @@ package body ZLib is | |||
301 | 307 | ||
302 | procedure Inflate_Init | 308 | procedure Inflate_Init |
303 | (Filter : in out Filter_Type; | 309 | (Filter : in out Filter_Type; |
304 | Window_Bits : in Window_Bits_Type := 15; | 310 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
305 | Header : in Header_Type := Default) | 311 | Header : in Header_Type := Default) |
306 | is | 312 | is |
307 | use type Thin.Int; | 313 | use type Thin.Int; |
@@ -320,6 +326,10 @@ package body ZLib is | |||
320 | end Check_Version; | 326 | end Check_Version; |
321 | 327 | ||
322 | begin | 328 | begin |
329 | if Is_Open (Filter) then | ||
330 | raise Status_Error; | ||
331 | end if; | ||
332 | |||
323 | case Header is | 333 | case Header is |
324 | when None => | 334 | when None => |
325 | Check_Version; | 335 | Check_Version; |
@@ -344,10 +354,9 @@ package body ZLib is | |||
344 | when Default => null; | 354 | when Default => null; |
345 | end case; | 355 | end case; |
346 | 356 | ||
347 | Filter.Strm := new Z_Stream; | 357 | Filter.Strm := new Z_Stream; |
348 | Filter.Compression := False; | 358 | Filter.Compression := False; |
349 | Filter.Stream_End := False; | 359 | Filter.Stream_End := False; |
350 | Filter.Opened := True; | ||
351 | Filter.Header := Header; | 360 | Filter.Header := Header; |
352 | 361 | ||
353 | if Thin.Inflate_Init | 362 | if Thin.Inflate_Init |
@@ -357,16 +366,25 @@ package body ZLib is | |||
357 | end if; | 366 | end if; |
358 | end Inflate_Init; | 367 | end Inflate_Init; |
359 | 368 | ||
369 | ------------- | ||
370 | -- Is_Open -- | ||
371 | ------------- | ||
372 | |||
373 | function Is_Open (Filter : in Filter_Type) return Boolean is | ||
374 | begin | ||
375 | return Filter.Strm /= null; | ||
376 | end Is_Open; | ||
377 | |||
360 | ----------------- | 378 | ----------------- |
361 | -- Raise_Error -- | 379 | -- Raise_Error -- |
362 | ----------------- | 380 | ----------------- |
363 | 381 | ||
364 | procedure Raise_Error (Message : String) is | 382 | procedure Raise_Error (Message : in String) is |
365 | begin | 383 | begin |
366 | Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message); | 384 | Ada.Exceptions.Raise_Exception (ZLib_Error'Identity, Message); |
367 | end Raise_Error; | 385 | end Raise_Error; |
368 | 386 | ||
369 | procedure Raise_Error (Stream : Z_Stream) is | 387 | procedure Raise_Error (Stream : in Z_Stream) is |
370 | begin | 388 | begin |
371 | Raise_Error (Last_Error_Message (Stream)); | 389 | Raise_Error (Last_Error_Message (Stream)); |
372 | end Raise_Error; | 390 | end Raise_Error; |
@@ -378,21 +396,29 @@ package body ZLib is | |||
378 | procedure Read | 396 | procedure Read |
379 | (Filter : in out Filter_Type; | 397 | (Filter : in out Filter_Type; |
380 | Item : out Ada.Streams.Stream_Element_Array; | 398 | Item : out Ada.Streams.Stream_Element_Array; |
381 | Last : out Ada.Streams.Stream_Element_Offset) | 399 | Last : out Ada.Streams.Stream_Element_Offset; |
400 | Flush : in Flush_Mode := No_Flush) | ||
382 | is | 401 | is |
383 | In_Last : Stream_Element_Offset; | 402 | In_Last : Stream_Element_Offset; |
384 | Item_First : Ada.Streams.Stream_Element_Offset := Item'First; | 403 | Item_First : Ada.Streams.Stream_Element_Offset := Item'First; |
404 | V_Flush : Flush_Mode := Flush; | ||
385 | 405 | ||
386 | begin | 406 | begin |
387 | pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1); | 407 | pragma Assert (Rest_First in Buffer'First .. Buffer'Last + 1); |
408 | pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last); | ||
388 | 409 | ||
389 | loop | 410 | loop |
390 | if Rest_First > Buffer'Last then | 411 | if Rest_Last = Buffer'First - 1 then |
412 | V_Flush := Finish; | ||
413 | |||
414 | elsif Rest_First > Rest_Last then | ||
391 | Read (Buffer, Rest_Last); | 415 | Read (Buffer, Rest_Last); |
392 | Rest_First := Buffer'First; | 416 | Rest_First := Buffer'First; |
393 | end if; | ||
394 | 417 | ||
395 | pragma Assert (Rest_Last in Buffer'First - 1 .. Buffer'Last); | 418 | if Rest_Last < Buffer'First then |
419 | V_Flush := Finish; | ||
420 | end if; | ||
421 | end if; | ||
396 | 422 | ||
397 | Translate | 423 | Translate |
398 | (Filter => Filter, | 424 | (Filter => Filter, |
@@ -400,11 +426,13 @@ package body ZLib is | |||
400 | In_Last => In_Last, | 426 | In_Last => In_Last, |
401 | Out_Data => Item (Item_First .. Item'Last), | 427 | Out_Data => Item (Item_First .. Item'Last), |
402 | Out_Last => Last, | 428 | Out_Last => Last, |
403 | Flush => Flush_Finish (Rest_Last < Rest_First)); | 429 | Flush => V_Flush); |
404 | 430 | ||
405 | Rest_First := In_Last + 1; | 431 | Rest_First := In_Last + 1; |
406 | 432 | ||
407 | exit when Last = Item'Last or else Stream_End (Filter); | 433 | exit when Stream_End (Filter) |
434 | or else Last = Item'Last | ||
435 | or else (Last >= Item'First and then Allow_Read_Some); | ||
408 | 436 | ||
409 | Item_First := Last + 1; | 437 | Item_First := Last + 1; |
410 | end loop; | 438 | end loop; |
@@ -489,11 +517,11 @@ package body ZLib is | |||
489 | Code : Thin.Int; | 517 | Code : Thin.Int; |
490 | 518 | ||
491 | begin | 519 | begin |
492 | if Filter.Opened = False then | 520 | if not Is_Open (Filter) then |
493 | raise ZLib_Error; | 521 | raise Status_Error; |
494 | end if; | 522 | end if; |
495 | 523 | ||
496 | if Out_Data'Length = 0 then | 524 | if Out_Data'Length = 0 and then In_Data'Length = 0 then |
497 | raise Constraint_Error; | 525 | raise Constraint_Error; |
498 | end if; | 526 | end if; |
499 | 527 | ||
@@ -514,7 +542,6 @@ package body ZLib is | |||
514 | - Stream_Element_Offset (Avail_In (Filter.Strm.all)); | 542 | - Stream_Element_Offset (Avail_In (Filter.Strm.all)); |
515 | Out_Last := Out_Data'Last | 543 | Out_Last := Out_Data'Last |
516 | - Stream_Element_Offset (Avail_Out (Filter.Strm.all)); | 544 | - Stream_Element_Offset (Avail_Out (Filter.Strm.all)); |
517 | |||
518 | end Translate_Auto; | 545 | end Translate_Auto; |
519 | 546 | ||
520 | -------------------- | 547 | -------------------- |
@@ -529,7 +556,7 @@ package body ZLib is | |||
529 | Out_Last : out Ada.Streams.Stream_Element_Offset; | 556 | Out_Last : out Ada.Streams.Stream_Element_Offset; |
530 | Flush : in Flush_Mode) | 557 | Flush : in Flush_Mode) |
531 | is | 558 | is |
532 | Out_First : Stream_Element_Offset; | 559 | Out_First : Stream_Element_Offset; |
533 | 560 | ||
534 | procedure Add_Data (Data : in Stream_Element_Array); | 561 | procedure Add_Data (Data : in Stream_Element_Array); |
535 | -- Add data to stream from the Filter.Offset till necessary, | 562 | -- Add data to stream from the Filter.Offset till necessary, |
@@ -596,7 +623,7 @@ package body ZLib is | |||
596 | Add_Data (Simple_GZip_Header); | 623 | Add_Data (Simple_GZip_Header); |
597 | 624 | ||
598 | Translate_Auto | 625 | Translate_Auto |
599 | (Filter => Filter, | 626 | (Filter => Filter, |
600 | In_Data => In_Data, | 627 | In_Data => In_Data, |
601 | In_Last => In_Last, | 628 | In_Last => In_Last, |
602 | Out_Data => Out_Data (Out_First .. Out_Data'Last), | 629 | Out_Data => Out_Data (Out_First .. Out_Data'Last), |
@@ -604,7 +631,6 @@ package body ZLib is | |||
604 | Flush => Flush); | 631 | Flush => Flush); |
605 | 632 | ||
606 | CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last)); | 633 | CRC32 (Filter.CRC, In_Data (In_Data'First .. In_Last)); |
607 | |||
608 | end if; | 634 | end if; |
609 | 635 | ||
610 | if Filter.Stream_End and then Out_Last <= Out_Data'Last then | 636 | if Filter.Stream_End and then Out_Last <= Out_Data'Last then |
@@ -642,10 +668,11 @@ package body ZLib is | |||
642 | procedure Write | 668 | procedure Write |
643 | (Filter : in out Filter_Type; | 669 | (Filter : in out Filter_Type; |
644 | Item : in Ada.Streams.Stream_Element_Array; | 670 | Item : in Ada.Streams.Stream_Element_Array; |
645 | Flush : in Flush_Mode) | 671 | Flush : in Flush_Mode := No_Flush) |
646 | is | 672 | is |
647 | Buffer : Stream_Element_Array (1 .. Buffer_Size); | 673 | Buffer : Stream_Element_Array (1 .. Buffer_Size); |
648 | In_Last, Out_Last : Stream_Element_Offset; | 674 | In_Last : Stream_Element_Offset; |
675 | Out_Last : Stream_Element_Offset; | ||
649 | In_First : Stream_Element_Offset := Item'First; | 676 | In_First : Stream_Element_Offset := Item'First; |
650 | begin | 677 | begin |
651 | if Item'Length = 0 and Flush = No_Flush then | 678 | if Item'Length = 0 and Flush = No_Flush then |
@@ -654,7 +681,7 @@ package body ZLib is | |||
654 | 681 | ||
655 | loop | 682 | loop |
656 | Translate | 683 | Translate |
657 | (Filter => Filter, | 684 | (Filter => Filter, |
658 | In_Data => Item (In_First .. Item'Last), | 685 | In_Data => Item (In_First .. Item'Last), |
659 | In_Last => In_Last, | 686 | In_Last => In_Last, |
660 | Out_Data => Buffer, | 687 | Out_Data => Buffer, |
diff --git a/contrib/ada/zlib.ads b/contrib/ada/zlib.ads index b72e4d2..79ffc40 100644 --- a/contrib/ada/zlib.ads +++ b/contrib/ada/zlib.ads | |||
@@ -1,7 +1,7 @@ | |||
1 | ------------------------------------------------------------------------------ | 1 | ------------------------------------------------------------------------------ |
2 | -- ZLib for Ada thick binding. -- | 2 | -- ZLib for Ada thick binding. -- |
3 | -- -- | 3 | -- -- |
4 | -- Copyright (C) 2002-2003 Dmitriy Anisimkov -- | 4 | -- Copyright (C) 2002-2004 Dmitriy Anisimkov -- |
5 | -- -- | 5 | -- -- |
6 | -- This library is free software; you can redistribute it and/or modify -- | 6 | -- This library is free software; you can redistribute it and/or modify -- |
7 | -- it under the terms of the GNU General Public License as published by -- | 7 | -- it under the terms of the GNU General Public License as published by -- |
@@ -25,7 +25,7 @@ | |||
25 | -- covered by the GNU Public License. -- | 25 | -- covered by the GNU Public License. -- |
26 | ------------------------------------------------------------------------------ | 26 | ------------------------------------------------------------------------------ |
27 | 27 | ||
28 | -- $Id: zlib.ads,v 1.17 2003/08/12 13:19:07 vagul Exp $ | 28 | -- $Id: zlib.ads,v 1.26 2004/09/06 06:53:19 vagul Exp $ |
29 | 29 | ||
30 | with Ada.Streams; | 30 | with Ada.Streams; |
31 | 31 | ||
@@ -33,7 +33,8 @@ with Interfaces; | |||
33 | 33 | ||
34 | package ZLib is | 34 | package ZLib is |
35 | 35 | ||
36 | ZLib_Error : exception; | 36 | ZLib_Error : exception; |
37 | Status_Error : exception; | ||
37 | 38 | ||
38 | type Compression_Level is new Integer range -1 .. 9; | 39 | type Compression_Level is new Integer range -1 .. 9; |
39 | 40 | ||
@@ -55,12 +56,15 @@ package ZLib is | |||
55 | 56 | ||
56 | subtype Count is Ada.Streams.Stream_Element_Count; | 57 | subtype Count is Ada.Streams.Stream_Element_Count; |
57 | 58 | ||
59 | Default_Memory_Level : constant Memory_Level_Type := 8; | ||
60 | Default_Window_Bits : constant Window_Bits_Type := 15; | ||
61 | |||
58 | ---------------------------------- | 62 | ---------------------------------- |
59 | -- Compression method constants -- | 63 | -- Compression method constants -- |
60 | ---------------------------------- | 64 | ---------------------------------- |
61 | 65 | ||
62 | Deflated : constant Compression_Method; | 66 | Deflated : constant Compression_Method; |
63 | -- Only one method allowed in this ZLib version. | 67 | -- Only one method allowed in this ZLib version |
64 | 68 | ||
65 | --------------------------------- | 69 | --------------------------------- |
66 | -- Compression level constants -- | 70 | -- Compression level constants -- |
@@ -79,21 +83,29 @@ package ZLib is | |||
79 | -- Regular way for compression, no flush | 83 | -- Regular way for compression, no flush |
80 | 84 | ||
81 | Partial_Flush : constant Flush_Mode; | 85 | Partial_Flush : constant Flush_Mode; |
82 | -- will be removed, use Z_SYNC_FLUSH instead | 86 | -- Will be removed, use Z_SYNC_FLUSH instead |
83 | 87 | ||
84 | Sync_Flush : constant Flush_Mode; | 88 | Sync_Flush : constant Flush_Mode; |
85 | -- all pending output is flushed to the output buffer and the output | 89 | -- All pending output is flushed to the output buffer and the output |
86 | -- is aligned on a byte boundary, so that the decompressor can get all | 90 | -- is aligned on a byte boundary, so that the decompressor can get all |
87 | -- input data available so far. (In particular avail_in is zero after the | 91 | -- input data available so far. (In particular avail_in is zero after the |
88 | -- call if enough output space has been provided before the call.) | 92 | -- call if enough output space has been provided before the call.) |
89 | -- Flushing may degrade compression for some compression algorithms and so | 93 | -- Flushing may degrade compression for some compression algorithms and so |
90 | -- it should be used only when necessary. | 94 | -- it should be used only when necessary. |
91 | 95 | ||
96 | Block_Flush : constant Flush_Mode; | ||
97 | -- Z_BLOCK requests that inflate() stop | ||
98 | -- if and when it get to the next deflate block boundary. When decoding the | ||
99 | -- zlib or gzip format, this will cause inflate() to return immediately | ||
100 | -- after the header and before the first block. When doing a raw inflate, | ||
101 | -- inflate() will go ahead and process the first block, and will return | ||
102 | -- when it gets to the end of that block, or when it runs out of data. | ||
103 | |||
92 | Full_Flush : constant Flush_Mode; | 104 | Full_Flush : constant Flush_Mode; |
93 | -- all output is flushed as with SYNC_FLUSH, and the compression state | 105 | -- All output is flushed as with SYNC_FLUSH, and the compression state |
94 | -- is reset so that decompression can restart from this point if previous | 106 | -- is reset so that decompression can restart from this point if previous |
95 | -- compressed data has been damaged or if random access is desired. Using | 107 | -- compressed data has been damaged or if random access is desired. Using |
96 | -- FULL_FLUSH too often can seriously degrade the compression. | 108 | -- Full_Flush too often can seriously degrade the compression. |
97 | 109 | ||
98 | Finish : constant Flush_Mode; | 110 | Finish : constant Flush_Mode; |
99 | -- Just for tell the compressor that input data is complete. | 111 | -- Just for tell the compressor that input data is complete. |
@@ -111,7 +123,7 @@ package ZLib is | |||
111 | 123 | ||
112 | Default_Buffer_Size : constant := 4096; | 124 | Default_Buffer_Size : constant := 4096; |
113 | 125 | ||
114 | type Filter_Type is limited private; | 126 | type Filter_Type is tagged limited private; |
115 | -- The filter is for compression and for decompression. | 127 | -- The filter is for compression and for decompression. |
116 | -- The usage of the type is depend of its initialization. | 128 | -- The usage of the type is depend of its initialization. |
117 | 129 | ||
@@ -124,8 +136,8 @@ package ZLib is | |||
124 | Level : in Compression_Level := Default_Compression; | 136 | Level : in Compression_Level := Default_Compression; |
125 | Strategy : in Strategy_Type := Default_Strategy; | 137 | Strategy : in Strategy_Type := Default_Strategy; |
126 | Method : in Compression_Method := Deflated; | 138 | Method : in Compression_Method := Deflated; |
127 | Window_Bits : in Window_Bits_Type := 15; | 139 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
128 | Memory_Level : in Memory_Level_Type := 8; | 140 | Memory_Level : in Memory_Level_Type := Default_Memory_Level; |
129 | Header : in Header_Type := Default); | 141 | Header : in Header_Type := Default); |
130 | -- Compressor initialization. | 142 | -- Compressor initialization. |
131 | -- When Header parameter is Auto or Default, then default zlib header | 143 | -- When Header parameter is Auto or Default, then default zlib header |
@@ -136,7 +148,7 @@ package ZLib is | |||
136 | 148 | ||
137 | procedure Inflate_Init | 149 | procedure Inflate_Init |
138 | (Filter : in out Filter_Type; | 150 | (Filter : in out Filter_Type; |
139 | Window_Bits : in Window_Bits_Type := 15; | 151 | Window_Bits : in Window_Bits_Type := Default_Window_Bits; |
140 | Header : in Header_Type := Default); | 152 | Header : in Header_Type := Default); |
141 | -- Decompressor initialization. | 153 | -- Decompressor initialization. |
142 | -- Default header type mean that ZLib default header is expecting in the | 154 | -- Default header type mean that ZLib default header is expecting in the |
@@ -146,10 +158,14 @@ package ZLib is | |||
146 | -- input compressed stream. | 158 | -- input compressed stream. |
147 | -- Auto header type mean that header type (GZip or Native) would be | 159 | -- Auto header type mean that header type (GZip or Native) would be |
148 | -- detected automatically in the input stream. | 160 | -- detected automatically in the input stream. |
149 | -- Note that header types parameter values None, GZip and Auto is | 161 | -- Note that header types parameter values None, GZip and Auto are |
150 | -- supporting for inflate routine only in ZLib versions 1.2.0.2 and later. | 162 | -- supported for inflate routine only in ZLib versions 1.2.0.2 and later. |
151 | -- Deflate_Init is supporting all header types. | 163 | -- Deflate_Init is supporting all header types. |
152 | 164 | ||
165 | function Is_Open (Filter : in Filter_Type) return Boolean; | ||
166 | pragma Inline (Is_Open); | ||
167 | -- Is the filter opened for compression or decompression. | ||
168 | |||
153 | procedure Close | 169 | procedure Close |
154 | (Filter : in out Filter_Type; | 170 | (Filter : in out Filter_Type; |
155 | Ignore_Error : in Boolean := False); | 171 | Ignore_Error : in Boolean := False); |
@@ -167,31 +183,31 @@ package ZLib is | |||
167 | (Filter : in out Filter_Type; | 183 | (Filter : in out Filter_Type; |
168 | In_Buffer_Size : in Integer := Default_Buffer_Size; | 184 | In_Buffer_Size : in Integer := Default_Buffer_Size; |
169 | Out_Buffer_Size : in Integer := Default_Buffer_Size); | 185 | Out_Buffer_Size : in Integer := Default_Buffer_Size); |
170 | -- Compressing/decompressing data arrived from Data_In routine | 186 | -- Compress/decompress data fetch from Data_In routine and pass the result |
171 | -- to the Data_Out routine. User should provide Data_In and Data_Out | 187 | -- to the Data_Out routine. User should provide Data_In and Data_Out |
172 | -- for compression/decompression data flow. | 188 | -- for compression/decompression data flow. |
173 | -- Compression or decompression depend on initialization of Filter. | 189 | -- Compression or decompression depend on Filter initialization. |
174 | 190 | ||
175 | function Total_In (Filter : in Filter_Type) return Count; | 191 | function Total_In (Filter : in Filter_Type) return Count; |
176 | pragma Inline (Total_In); | 192 | pragma Inline (Total_In); |
177 | -- Return total number of input bytes read so far. | 193 | -- Returns total number of input bytes read so far |
178 | 194 | ||
179 | function Total_Out (Filter : in Filter_Type) return Count; | 195 | function Total_Out (Filter : in Filter_Type) return Count; |
180 | pragma Inline (Total_Out); | 196 | pragma Inline (Total_Out); |
181 | -- Return total number of bytes output so far. | 197 | -- Returns total number of bytes output so far |
182 | 198 | ||
183 | function CRC32 | 199 | function CRC32 |
184 | (CRC : in Unsigned_32; | 200 | (CRC : in Unsigned_32; |
185 | Data : in Ada.Streams.Stream_Element_Array) | 201 | Data : in Ada.Streams.Stream_Element_Array) |
186 | return Unsigned_32; | 202 | return Unsigned_32; |
187 | pragma Inline (CRC32); | 203 | pragma Inline (CRC32); |
188 | -- Calculate CRC32, it could be necessary for make gzip format. | 204 | -- Compute CRC32, it could be necessary for make gzip format |
189 | 205 | ||
190 | procedure CRC32 | 206 | procedure CRC32 |
191 | (CRC : in out Unsigned_32; | 207 | (CRC : in out Unsigned_32; |
192 | Data : in Ada.Streams.Stream_Element_Array); | 208 | Data : in Ada.Streams.Stream_Element_Array); |
193 | pragma Inline (CRC32); | 209 | pragma Inline (CRC32); |
194 | -- Calculate CRC32, it could be necessary for make gzip format. | 210 | -- Compute CRC32, it could be necessary for make gzip format |
195 | 211 | ||
196 | ------------------------------------------------- | 212 | ------------------------------------------------- |
197 | -- Below is more complex low level routines. -- | 213 | -- Below is more complex low level routines. -- |
@@ -204,15 +220,11 @@ package ZLib is | |||
204 | Out_Data : out Ada.Streams.Stream_Element_Array; | 220 | Out_Data : out Ada.Streams.Stream_Element_Array; |
205 | Out_Last : out Ada.Streams.Stream_Element_Offset; | 221 | Out_Last : out Ada.Streams.Stream_Element_Offset; |
206 | Flush : in Flush_Mode); | 222 | Flush : in Flush_Mode); |
207 | -- Compressing/decompressing the datas from In_Data buffer to the | 223 | -- Compress/decompress the In_Data buffer and place the result into |
208 | -- Out_Data buffer. | 224 | -- Out_Data. In_Last is the index of last element from In_Data accepted by |
209 | -- In_Data is incoming data portion, | 225 | -- the Filter. Out_Last is the last element of the received data from |
210 | -- In_Last is the index of last element from In_Data accepted by the | 226 | -- Filter. To tell the filter that incoming data are complete put the |
211 | -- Filter. | 227 | -- Flush parameter to Finish. |
212 | -- Out_Data is the buffer for output data from the filter. | ||
213 | -- Out_Last is the last element of the received data from Filter. | ||
214 | -- To tell the filter that incoming data is complete put the | ||
215 | -- Flush parameter to FINISH. | ||
216 | 228 | ||
217 | function Stream_End (Filter : in Filter_Type) return Boolean; | 229 | function Stream_End (Filter : in Filter_Type) return Boolean; |
218 | pragma Inline (Stream_End); | 230 | pragma Inline (Stream_End); |
@@ -239,10 +251,9 @@ package ZLib is | |||
239 | procedure Write | 251 | procedure Write |
240 | (Filter : in out Filter_Type; | 252 | (Filter : in out Filter_Type; |
241 | Item : in Ada.Streams.Stream_Element_Array; | 253 | Item : in Ada.Streams.Stream_Element_Array; |
242 | Flush : in Flush_Mode); | 254 | Flush : in Flush_Mode := No_Flush); |
243 | -- Compressing/Decompressing data from Item to the | 255 | -- Compress/Decompress data from Item to the generic parameter procedure |
244 | -- generic parameter procedure Write. | 256 | -- Write. Output buffer size could be set in Buffer_Size generic parameter. |
245 | -- Output buffer size could be set in Buffer_Size generic parameter. | ||
246 | 257 | ||
247 | generic | 258 | generic |
248 | with procedure Read | 259 | with procedure Read |
@@ -257,33 +268,41 @@ package ZLib is | |||
257 | 268 | ||
258 | Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; | 269 | Rest_First, Rest_Last : in out Ada.Streams.Stream_Element_Offset; |
259 | -- Rest_First have to be initialized to Buffer'Last + 1 | 270 | -- Rest_First have to be initialized to Buffer'Last + 1 |
271 | -- Rest_Last have to be initialized to Buffer'Last | ||
260 | -- before usage. | 272 | -- before usage. |
261 | 273 | ||
274 | Allow_Read_Some : in Boolean := False; | ||
275 | -- Is it allowed to return Last < Item'Last before end of data. | ||
276 | |||
262 | procedure Read | 277 | procedure Read |
263 | (Filter : in out Filter_Type; | 278 | (Filter : in out Filter_Type; |
264 | Item : out Ada.Streams.Stream_Element_Array; | 279 | Item : out Ada.Streams.Stream_Element_Array; |
265 | Last : out Ada.Streams.Stream_Element_Offset); | 280 | Last : out Ada.Streams.Stream_Element_Offset; |
266 | -- Compressing/Decompressing data from generic parameter | 281 | Flush : in Flush_Mode := No_Flush); |
267 | -- procedure Read to the Item. | 282 | -- Compress/Decompress data from generic parameter procedure Read to the |
268 | -- User should provide Buffer for the operation | 283 | -- Item. User should provide Buffer and initialized Rest_First, Rest_Last |
269 | -- and Rest_First variable first time initialized to the Buffer'Last + 1. | 284 | -- indicators. If Allow_Read_Some is True, Read routines could return |
285 | -- Last < Item'Last only at end of stream. | ||
270 | 286 | ||
271 | private | 287 | private |
272 | 288 | ||
273 | use Ada.Streams; | 289 | use Ada.Streams; |
274 | 290 | ||
275 | type Flush_Mode is new Integer range 0 .. 4; | 291 | pragma Assert (Ada.Streams.Stream_Element'Size = 8); |
292 | pragma Assert (Ada.Streams.Stream_Element'Modulus = 2**8); | ||
293 | |||
294 | type Flush_Mode is new Integer range 0 .. 5; | ||
276 | 295 | ||
277 | type Compression_Method is new Integer range 8 .. 8; | 296 | type Compression_Method is new Integer range 8 .. 8; |
278 | 297 | ||
279 | type Strategy_Type is new Integer range 0 .. 3; | 298 | type Strategy_Type is new Integer range 0 .. 3; |
280 | 299 | ||
281 | No_Flush : constant Flush_Mode := 0; | 300 | No_Flush : constant Flush_Mode := 0; |
301 | Partial_Flush : constant Flush_Mode := 1; | ||
282 | Sync_Flush : constant Flush_Mode := 2; | 302 | Sync_Flush : constant Flush_Mode := 2; |
283 | Full_Flush : constant Flush_Mode := 3; | 303 | Full_Flush : constant Flush_Mode := 3; |
284 | Finish : constant Flush_Mode := 4; | 304 | Finish : constant Flush_Mode := 4; |
285 | Partial_Flush : constant Flush_Mode := 1; | 305 | Block_Flush : constant Flush_Mode := 5; |
286 | -- will be removed, use Z_SYNC_FLUSH instead | ||
287 | 306 | ||
288 | Filtered : constant Strategy_Type := 1; | 307 | Filtered : constant Strategy_Type := 1; |
289 | Huffman_Only : constant Strategy_Type := 2; | 308 | Huffman_Only : constant Strategy_Type := 2; |
@@ -296,7 +315,7 @@ private | |||
296 | 315 | ||
297 | type Z_Stream_Access is access all Z_Stream; | 316 | type Z_Stream_Access is access all Z_Stream; |
298 | 317 | ||
299 | type Filter_Type is record | 318 | type Filter_Type is tagged limited record |
300 | Strm : Z_Stream_Access; | 319 | Strm : Z_Stream_Access; |
301 | Compression : Boolean; | 320 | Compression : Boolean; |
302 | Stream_End : Boolean; | 321 | Stream_End : Boolean; |
@@ -304,8 +323,6 @@ private | |||
304 | CRC : Unsigned_32; | 323 | CRC : Unsigned_32; |
305 | Offset : Stream_Element_Offset; | 324 | Offset : Stream_Element_Offset; |
306 | -- Offset for gzip header/footer output. | 325 | -- Offset for gzip header/footer output. |
307 | |||
308 | Opened : Boolean := False; | ||
309 | end record; | 326 | end record; |
310 | 327 | ||
311 | end ZLib; | 328 | end ZLib; |
diff --git a/contrib/ada/zlib.gpr b/contrib/ada/zlib.gpr index 0f58985..88f51cc 100644 --- a/contrib/ada/zlib.gpr +++ b/contrib/ada/zlib.gpr | |||
@@ -1,21 +1,21 @@ | |||
1 | project Zlib is | 1 | project Zlib is |
2 | 2 | ||
3 | for Languages use ("Ada"); | 3 | for Languages use ("Ada"); |
4 | for Source_Dirs use ("."); | 4 | for Source_Dirs use ("."); |
5 | for Object_Dir use "."; | 5 | for Object_Dir use "."; |
6 | for Main use ("test.adb", "mtest.adb", "read.adb"); | 6 | for Main use ("test.adb", "mtest.adb", "read.adb", "buffer_demo"); |
7 | 7 | ||
8 | package Compiler is | 8 | package Compiler is |
9 | for Default_Switches ("ada") use ("-gnatwbcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst"); | 9 | for Default_Switches ("ada") use ("-gnatwcfilopru", "-gnatVcdfimorst", "-gnatyabcefhiklmnoprst"); |
10 | end Compiler; | 10 | end Compiler; |
11 | 11 | ||
12 | package Linker is | 12 | package Linker is |
13 | for Default_Switches ("ada") use ("-lz"); | 13 | for Default_Switches ("ada") use ("-lz"); |
14 | end Linker; | 14 | end Linker; |
15 | 15 | ||
16 | package Builder is | 16 | package Builder is |
17 | for Default_Switches ("ada") use ("-s", "-gnatQ"); | 17 | for Default_Switches ("ada") use ("-s", "-gnatQ"); |
18 | end Builder; | 18 | end Builder; |
19 | 19 | ||
20 | end Zlib; | 20 | end Zlib; |
21 | 21 | ||
diff --git a/contrib/delphi/ZLib.pas b/contrib/delphi/ZLib.pas index 61ffd08..8853866 100644 --- a/contrib/delphi/ZLib.pas +++ b/contrib/delphi/ZLib.pas | |||
@@ -152,7 +152,7 @@ procedure DecompressToUserBuf(const InBuf: Pointer; InBytes: Integer; | |||
152 | const OutBuf: Pointer; BufSize: Integer); | 152 | const OutBuf: Pointer; BufSize: Integer); |
153 | 153 | ||
154 | const | 154 | const |
155 | zlib_version = '1.2.1'; | 155 | zlib_version = '1.2.2'; |
156 | 156 | ||
157 | type | 157 | type |
158 | EZlibError = class(Exception); | 158 | EZlibError = class(Exception); |
@@ -510,7 +510,7 @@ begin | |||
510 | Result := Count - FZRec.avail_out; | 510 | Result := Count - FZRec.avail_out; |
511 | Exit; | 511 | Exit; |
512 | end; | 512 | end; |
513 | FZRec.next_in := FBuffer; | 513 | FZRec.next_in := FBuffer; |
514 | FStrmPos := FStrm.Position; | 514 | FStrmPos := FStrm.Position; |
515 | Progress(Self); | 515 | Progress(Self); |
516 | end; | 516 | end; |
diff --git a/contrib/infback9/infback9.c b/contrib/infback9/infback9.c index 34a95fc..103d901 100644 --- a/contrib/infback9/infback9.c +++ b/contrib/infback9/infback9.c | |||
@@ -430,6 +430,9 @@ void FAR *out_desc; | |||
430 | } | 430 | } |
431 | } | 431 | } |
432 | 432 | ||
433 | /* handle error breaks in while */ | ||
434 | if (mode == BAD) break; | ||
435 | |||
433 | /* build code tables */ | 436 | /* build code tables */ |
434 | state->next = state->codes; | 437 | state->next = state->codes; |
435 | lencode = (code const FAR *)(state->next); | 438 | lencode = (code const FAR *)(state->next); |
diff --git a/contrib/infback9/inftree9.c b/contrib/infback9/inftree9.c index 337a277..5fd5b4a 100644 --- a/contrib/infback9/inftree9.c +++ b/contrib/infback9/inftree9.c | |||
@@ -9,7 +9,7 @@ | |||
9 | #define MAXBITS 15 | 9 | #define MAXBITS 15 |
10 | 10 | ||
11 | const char inflate9_copyright[] = | 11 | const char inflate9_copyright[] = |
12 | " inflate9 1.2.1.1 Copyright 1995-2003 Mark Adler "; | 12 | " inflate9 1.2.1.2 Copyright 1995-2004 Mark Adler "; |
13 | /* | 13 | /* |
14 | If you use the zlib library in a product, an acknowledgment is welcome | 14 | If you use the zlib library in a product, an acknowledgment is welcome |
15 | in the documentation of your product. If for some reason you cannot | 15 | in the documentation of your product. If for some reason you cannot |
@@ -64,7 +64,7 @@ unsigned short FAR *work; | |||
64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ | 64 | static const unsigned short lext[31] = { /* Length codes 257..285 extra */ |
65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, | 65 | 128, 128, 128, 128, 128, 128, 128, 128, 129, 129, 129, 129, |
66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, | 66 | 130, 130, 130, 130, 131, 131, 131, 131, 132, 132, 132, 132, |
67 | 133, 133, 133, 133, 144, 202, 196}; | 67 | 133, 133, 133, 133, 144, 77, 194}; |
68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ | 68 | static const unsigned short dbase[32] = { /* Distance codes 0..31 base */ |
69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, | 69 | 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, |
70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, | 70 | 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, |
diff --git a/contrib/masmx86/mkasm.bat b/contrib/masmx86/mkasm.bat index f3fa0a0..70a51f8 100755 --- a/contrib/masmx86/mkasm.bat +++ b/contrib/masmx86/mkasm.bat | |||
@@ -1,3 +1,3 @@ | |||
1 | cl /I..\.. /O2 /c gvmat32c.c | 1 | cl /DASMV /I..\.. /O2 /c gvmat32c.c |
2 | ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm | 2 | ml /coff /Zi /c /Flgvmat32.lst gvmat32.asm |
3 | ml /coff /Zi /c /Flinffas32.lst inffas32.asm | 3 | ml /coff /Zi /c /Flinffas32.lst inffas32.asm |
diff --git a/contrib/minizip/ChangeLogUnzip b/contrib/minizip/ChangeLogUnzip index d7d4b6b..4be4d16 100644 --- a/contrib/minizip/ChangeLogUnzip +++ b/contrib/minizip/ChangeLogUnzip | |||
@@ -1,3 +1,11 @@ | |||
1 | Change in 1.01b (20 may 04) | ||
2 | - Integrate patch from Debian package (submited by Mark Brown) | ||
3 | - Add tools mztools from Xavier Roche | ||
4 | |||
5 | Change in 1.01 (8 may 04) | ||
6 | - fix buffer overrun risk in unzip.c (Xavier Roche) | ||
7 | - fix a minor buffer insecurity in minizip.c (Mike Whittaker) | ||
8 | |||
1 | Change in 1.00: (10 sept 03) | 9 | Change in 1.00: (10 sept 03) |
2 | - rename to 1.00 | 10 | - rename to 1.00 |
3 | - cosmetic code change | 11 | - cosmetic code change |
diff --git a/contrib/minizip/crypt.h b/contrib/minizip/crypt.h index 9c7a89c..7f8a634 100644 --- a/contrib/minizip/crypt.h +++ b/contrib/minizip/crypt.h | |||
@@ -1,9 +1,9 @@ | |||
1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile | 1 | /* crypt.h -- base code for crypt/uncrypt ZIPfile |
2 | 2 | ||
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | 7 | ||
8 | This code is a modified version of crypting code in Infozip distribution | 8 | This code is a modified version of crypting code in Infozip distribution |
9 | 9 | ||
diff --git a/contrib/minizip/ioapi.c b/contrib/minizip/ioapi.c index 80443b7..6ddfd36 100644 --- a/contrib/minizip/ioapi.c +++ b/contrib/minizip/ioapi.c | |||
@@ -1,9 +1,9 @@ | |||
1 | /* ioapi.c -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.c -- IO base function header for compress/uncompress .zip |
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <stdio.h> | 9 | #include <stdio.h> |
diff --git a/contrib/minizip/ioapi.h b/contrib/minizip/ioapi.h index 6bc2a2c..b761161 100644 --- a/contrib/minizip/ioapi.h +++ b/contrib/minizip/ioapi.h | |||
@@ -1,9 +1,9 @@ | |||
1 | /* ioapi.h -- IO base function header for compress/uncompress .zip | 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip |
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | 3 | ||
4 | Version 1.00, September 10th, 2003 | 4 | Version 1.01, May 8th, 2004 |
5 | 5 | ||
6 | Copyright (C) 1998-2003 Gilles Vollant | 6 | Copyright (C) 1998-2004 Gilles Vollant |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #ifndef _ZLIBIOAPI_H | 9 | #ifndef _ZLIBIOAPI_H |
diff --git a/contrib/minizip/iowin32.c b/contrib/minizip/iowin32.c index 02b27cb..940dc0b 100644 --- a/contrib/minizip/iowin32.c +++ b/contrib/minizip/iowin32.c | |||
@@ -2,9 +2,9 @@ | |||
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | This IO API version uses the Win32 API (for Microsoft Windows) |
4 | 4 | ||
5 | Version 1.00, September 10th, 2003 | 5 | Version 1.01, May 8th, 2004 |
6 | 6 | ||
7 | Copyright (C) 1998-2003 Gilles Vollant | 7 | Copyright (C) 1998-2004 Gilles Vollant |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <stdlib.h> | 10 | #include <stdlib.h> |
diff --git a/contrib/minizip/iowin32.h b/contrib/minizip/iowin32.h index c0ebd50..8774fe7 100644 --- a/contrib/minizip/iowin32.h +++ b/contrib/minizip/iowin32.h | |||
@@ -2,9 +2,9 @@ | |||
2 | files using zlib + zip or unzip API | 2 | files using zlib + zip or unzip API |
3 | This IO API version uses the Win32 API (for Microsoft Windows) | 3 | This IO API version uses the Win32 API (for Microsoft Windows) |
4 | 4 | ||
5 | Version 1.00, September 10th, 2003 | 5 | Version 1.01, May 8th, 2004 |
6 | 6 | ||
7 | Copyright (C) 1998-2003 Gilles Vollant | 7 | Copyright (C) 1998-2004 Gilles Vollant |
8 | */ | 8 | */ |
9 | 9 | ||
10 | #include <windows.h> | 10 | #include <windows.h> |
diff --git a/contrib/minizip/miniunz.c b/contrib/minizip/miniunz.c index c8cf81e..11b7260 100644 --- a/contrib/minizip/miniunz.c +++ b/contrib/minizip/miniunz.c | |||
@@ -1,3 +1,11 @@ | |||
1 | /* | ||
2 | miniunz.c | ||
3 | Version 1.01b, May 30th, 2004 | ||
4 | |||
5 | Copyright (C) 1998-2004 Gilles Vollant | ||
6 | */ | ||
7 | |||
8 | |||
1 | #include <stdio.h> | 9 | #include <stdio.h> |
2 | #include <stdlib.h> | 10 | #include <stdlib.h> |
3 | #include <string.h> | 11 | #include <string.h> |
@@ -27,7 +35,7 @@ | |||
27 | mini unzip, demo of unzip package | 35 | mini unzip, demo of unzip package |
28 | 36 | ||
29 | usage : | 37 | usage : |
30 | Usage : miniunz [-exvlo] file.zip [file_to_extract] | 38 | Usage : miniunz [-exvlo] file.zip [file_to_extract] [-d extractdir] |
31 | 39 | ||
32 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT | 40 | list the file in the zipfile, and print the content of FILE_ID.ZIP or README.TXT |
33 | if it exists | 41 | if it exists |
@@ -140,17 +148,18 @@ int makedir (newdir) | |||
140 | 148 | ||
141 | void do_banner() | 149 | void do_banner() |
142 | { | 150 | { |
143 | printf("MiniUnz 1.00, demo of zLib + Unz package written by Gilles Vollant\n"); | 151 | printf("MiniUnz 1.01b, demo of zLib + Unz package written by Gilles Vollant\n"); |
144 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 152 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
145 | } | 153 | } |
146 | 154 | ||
147 | void do_help() | 155 | void do_help() |
148 | { | 156 | { |
149 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.]\n\n" \ | 157 | printf("Usage : miniunz [-e] [-x] [-v] [-l] [-o] [-p password] file.zip [file_to_extr.] [-d extractdir]\n\n" \ |
150 | " -e Extract without pathname (junk paths)\n" \ | 158 | " -e Extract without pathname (junk paths)\n" \ |
151 | " -x Extract with pathname\n" \ | 159 | " -x Extract with pathname\n" \ |
152 | " -v list files\n" \ | 160 | " -v list files\n" \ |
153 | " -l list files\n" \ | 161 | " -l list files\n" \ |
162 | " -d directory to extract into\n" \ | ||
154 | " -o overwrite files without prompting\n" \ | 163 | " -o overwrite files without prompting\n" \ |
155 | " -p extract crypted file using password\n\n"); | 164 | " -p extract crypted file using password\n\n"); |
156 | } | 165 | } |
@@ -304,8 +313,14 @@ int do_extract_currentfile(uf,popt_extract_without_path,popt_overwrite,password) | |||
304 | do | 313 | do |
305 | { | 314 | { |
306 | char answer[128]; | 315 | char answer[128]; |
307 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | 316 | int ret; |
308 | scanf("%1s",answer); | 317 | |
318 | printf("The file %s exists. Overwrite ? [y]es, [n]o, [A]ll: ",write_filename); | ||
319 | ret = scanf("%1s",answer); | ||
320 | if (ret != 1) | ||
321 | { | ||
322 | exit(EXIT_FAILURE); | ||
323 | } | ||
309 | rep = answer[0] ; | 324 | rep = answer[0] ; |
310 | if ((rep>='a') && (rep<='z')) | 325 | if ((rep>='a') && (rep<='z')) |
311 | rep -= 0x20; | 326 | rep -= 0x20; |
@@ -459,6 +474,8 @@ int main(argc,argv) | |||
459 | int opt_do_extract=1; | 474 | int opt_do_extract=1; |
460 | int opt_do_extract_withoutpath=0; | 475 | int opt_do_extract_withoutpath=0; |
461 | int opt_overwrite=0; | 476 | int opt_overwrite=0; |
477 | int opt_extractdir=0; | ||
478 | const char *dirname=NULL; | ||
462 | unzFile uf=NULL; | 479 | unzFile uf=NULL; |
463 | 480 | ||
464 | do_banner(); | 481 | do_banner(); |
@@ -488,6 +505,12 @@ int main(argc,argv) | |||
488 | opt_do_extract = opt_do_extract_withoutpath = 1; | 505 | opt_do_extract = opt_do_extract_withoutpath = 1; |
489 | if ((c=='o') || (c=='O')) | 506 | if ((c=='o') || (c=='O')) |
490 | opt_overwrite=1; | 507 | opt_overwrite=1; |
508 | if ((c=='d') || (c=='D')) | ||
509 | { | ||
510 | opt_extractdir=1; | ||
511 | dirname=argv[i+1]; | ||
512 | } | ||
513 | |||
491 | if (((c=='p') || (c=='P')) && (i+1<argc)) | 514 | if (((c=='p') || (c=='P')) && (i+1<argc)) |
492 | { | 515 | { |
493 | password=argv[i+1]; | 516 | password=argv[i+1]; |
@@ -499,7 +522,7 @@ int main(argc,argv) | |||
499 | { | 522 | { |
500 | if (zipfilename == NULL) | 523 | if (zipfilename == NULL) |
501 | zipfilename = argv[i]; | 524 | zipfilename = argv[i]; |
502 | else if (filename_to_extract==NULL) | 525 | else if ((filename_to_extract==NULL) && (!opt_extractdir)) |
503 | filename_to_extract = argv[i] ; | 526 | filename_to_extract = argv[i] ; |
504 | } | 527 | } |
505 | } | 528 | } |
@@ -544,6 +567,12 @@ int main(argc,argv) | |||
544 | return do_list(uf); | 567 | return do_list(uf); |
545 | else if (opt_do_extract==1) | 568 | else if (opt_do_extract==1) |
546 | { | 569 | { |
570 | if (opt_extractdir && chdir(dirname)) | ||
571 | { | ||
572 | printf("Error changing into %s, aborting\n", dirname); | ||
573 | exit(-1); | ||
574 | } | ||
575 | |||
547 | if (filename_to_extract == NULL) | 576 | if (filename_to_extract == NULL) |
548 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); | 577 | return do_extract(uf,opt_do_extract_withoutpath,opt_overwrite,password); |
549 | else | 578 | else |
diff --git a/contrib/minizip/minizip.c b/contrib/minizip/minizip.c index 5746f5c..918c322 100644 --- a/contrib/minizip/minizip.c +++ b/contrib/minizip/minizip.c | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | minizip.c | ||
3 | Version 1.01b, May 30th, 2004 | ||
4 | |||
5 | Copyright (C) 1998-2004 Gilles Vollant | ||
6 | */ | ||
7 | |||
1 | #include <stdio.h> | 8 | #include <stdio.h> |
2 | #include <stdlib.h> | 9 | #include <stdlib.h> |
3 | #include <string.h> | 10 | #include <string.h> |
@@ -53,8 +60,8 @@ uLong filetime(f, tmzip, dt) | |||
53 | #else | 60 | #else |
54 | #ifdef unix | 61 | #ifdef unix |
55 | uLong filetime(f, tmzip, dt) | 62 | uLong filetime(f, tmzip, dt) |
56 | char *f; /* name of file to get info on */ | 63 | char *f; /* name of file to get info on */ |
57 | tm_zip *tmzip; /* return value: access, modific. and creation times */ | 64 | tm_zip *tmzip; /* return value: access, modific. and creation times */ |
58 | uLong *dt; /* dostime */ | 65 | uLong *dt; /* dostime */ |
59 | { | 66 | { |
60 | int ret=0; | 67 | int ret=0; |
@@ -66,6 +73,8 @@ uLong filetime(f, tmzip, dt) | |||
66 | { | 73 | { |
67 | char name[MAXFILENAME+1]; | 74 | char name[MAXFILENAME+1]; |
68 | int len = strlen(f); | 75 | int len = strlen(f); |
76 | if (len > MAXFILENAME) | ||
77 | len = MAXFILENAME; | ||
69 | 78 | ||
70 | strncpy(name, f,MAXFILENAME-1); | 79 | strncpy(name, f,MAXFILENAME-1); |
71 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ | 80 | /* strncpy doesnt append the trailing NULL, of the string is too long. */ |
@@ -120,7 +129,7 @@ int check_exist_file(filename) | |||
120 | 129 | ||
121 | void do_banner() | 130 | void do_banner() |
122 | { | 131 | { |
123 | printf("MiniZip 1.00, demo of zLib + Zip package written by Gilles Vollant\n"); | 132 | printf("MiniZip 1.01b, demo of zLib + Zip package written by Gilles Vollant\n"); |
124 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); | 133 | printf("more info at http://www.winimage.com/zLibDll/unzip.html\n\n"); |
125 | } | 134 | } |
126 | 135 | ||
@@ -269,8 +278,13 @@ int main(argc,argv) | |||
269 | do | 278 | do |
270 | { | 279 | { |
271 | char answer[128]; | 280 | char answer[128]; |
272 | printf("The file %s exist. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); | 281 | int ret; |
273 | scanf("%1s",answer); | 282 | printf("The file %s exists. Overwrite ? [y]es, [n]o, [a]ppend : ",filename_try); |
283 | ret = scanf("%1s",answer); | ||
284 | if (ret != 1) | ||
285 | { | ||
286 | exit(EXIT_FAILURE); | ||
287 | } | ||
274 | rep = answer[0] ; | 288 | rep = answer[0] ; |
275 | if ((rep>='a') && (rep<='z')) | 289 | if ((rep>='a') && (rep<='z')) |
276 | rep -= 0x20; | 290 | rep -= 0x20; |
@@ -305,7 +319,12 @@ int main(argc,argv) | |||
305 | 319 | ||
306 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) | 320 | for (i=zipfilenamearg+1;(i<argc) && (err==ZIP_OK);i++) |
307 | { | 321 | { |
308 | if (((*(argv[i]))!='-') && ((*(argv[i]))!='/')) | 322 | if (!((((*(argv[i]))=='-') || ((*(argv[i]))=='/')) && |
323 | ((argv[i][1]=='o') || (argv[i][1]=='O') || | ||
324 | (argv[i][1]=='a') || (argv[i][1]=='A') || | ||
325 | (argv[i][1]=='p') || (argv[i][1]=='P') || | ||
326 | ((argv[i][1]>='0') || (argv[i][1]<='9'))) && | ||
327 | (strlen(argv[i]) == 2))) | ||
309 | { | 328 | { |
310 | FILE * fin; | 329 | FILE * fin; |
311 | int size_read; | 330 | int size_read; |
@@ -390,7 +409,11 @@ int main(argc,argv) | |||
390 | errclose = zipClose(zf,NULL); | 409 | errclose = zipClose(zf,NULL); |
391 | if (errclose != ZIP_OK) | 410 | if (errclose != ZIP_OK) |
392 | printf("error in closing %s\n",filename_try); | 411 | printf("error in closing %s\n",filename_try); |
393 | } | 412 | } |
413 | else | ||
414 | { | ||
415 | do_help(); | ||
416 | } | ||
394 | 417 | ||
395 | free(buf); | 418 | free(buf); |
396 | return 0; | 419 | return 0; |
diff --git a/contrib/minizip/mztools.c b/contrib/minizip/mztools.c new file mode 100644 index 0000000..363ee13 --- /dev/null +++ b/contrib/minizip/mztools.c | |||
@@ -0,0 +1,281 @@ | |||
1 | /* | ||
2 | Additional tools for Minizip | ||
3 | Code: Xavier Roche '2004 | ||
4 | License: Same as ZLIB (www.gzip.org) | ||
5 | */ | ||
6 | |||
7 | /* Code */ | ||
8 | #include <stdio.h> | ||
9 | #include <stdlib.h> | ||
10 | #include <string.h> | ||
11 | #include "zlib.h" | ||
12 | #include "unzip.h" | ||
13 | |||
14 | #define READ_8(adr) ((unsigned char)*(adr)) | ||
15 | #define READ_16(adr) ( READ_8(adr) | (READ_8(adr+1) << 8) ) | ||
16 | #define READ_32(adr) ( READ_16(adr) | (READ_16((adr)+2) << 16) ) | ||
17 | |||
18 | #define WRITE_8(buff, n) do { \ | ||
19 | *((unsigned char*)(buff)) = (unsigned char) ((n) & 0xff); \ | ||
20 | } while(0) | ||
21 | #define WRITE_16(buff, n) do { \ | ||
22 | WRITE_8((unsigned char*)(buff), n); \ | ||
23 | WRITE_8(((unsigned char*)(buff)) + 1, (n) >> 8); \ | ||
24 | } while(0) | ||
25 | #define WRITE_32(buff, n) do { \ | ||
26 | WRITE_16((unsigned char*)(buff), (n) & 0xffff); \ | ||
27 | WRITE_16((unsigned char*)(buff) + 2, (n) >> 16); \ | ||
28 | } while(0) | ||
29 | |||
30 | extern int ZEXPORT unzRepair(file, fileOut, fileOutTmp, nRecovered, bytesRecovered) | ||
31 | const char* file; | ||
32 | const char* fileOut; | ||
33 | const char* fileOutTmp; | ||
34 | uLong* nRecovered; | ||
35 | uLong* bytesRecovered; | ||
36 | { | ||
37 | int err = Z_OK; | ||
38 | FILE* fpZip = fopen(file, "rb"); | ||
39 | FILE* fpOut = fopen(fileOut, "wb"); | ||
40 | FILE* fpOutCD = fopen(fileOutTmp, "wb"); | ||
41 | if (fpZip != NULL && fpOut != NULL) { | ||
42 | int entries = 0; | ||
43 | uLong totalBytes = 0; | ||
44 | char header[30]; | ||
45 | char filename[256]; | ||
46 | char extra[1024]; | ||
47 | int offset = 0; | ||
48 | int offsetCD = 0; | ||
49 | while ( fread(header, 1, 30, fpZip) == 30 ) { | ||
50 | int currentOffset = offset; | ||
51 | |||
52 | /* File entry */ | ||
53 | if (READ_32(header) == 0x04034b50) { | ||
54 | unsigned int version = READ_16(header + 4); | ||
55 | unsigned int gpflag = READ_16(header + 6); | ||
56 | unsigned int method = READ_16(header + 8); | ||
57 | unsigned int filetime = READ_16(header + 10); | ||
58 | unsigned int filedate = READ_16(header + 12); | ||
59 | unsigned int crc = READ_32(header + 14); /* crc */ | ||
60 | unsigned int cpsize = READ_32(header + 18); /* compressed size */ | ||
61 | unsigned int uncpsize = READ_32(header + 22); /* uncompressed sz */ | ||
62 | unsigned int fnsize = READ_16(header + 26); /* file name length */ | ||
63 | unsigned int extsize = READ_16(header + 28); /* extra field length */ | ||
64 | filename[0] = extra[0] = '\0'; | ||
65 | |||
66 | /* Header */ | ||
67 | if (fwrite(header, 1, 30, fpOut) == 30) { | ||
68 | offset += 30; | ||
69 | } else { | ||
70 | err = Z_ERRNO; | ||
71 | break; | ||
72 | } | ||
73 | |||
74 | /* Filename */ | ||
75 | if (fnsize > 0) { | ||
76 | if (fread(filename, 1, fnsize, fpZip) == fnsize) { | ||
77 | if (fwrite(filename, 1, fnsize, fpOut) == fnsize) { | ||
78 | offset += fnsize; | ||
79 | } else { | ||
80 | err = Z_ERRNO; | ||
81 | break; | ||
82 | } | ||
83 | } else { | ||
84 | err = Z_ERRNO; | ||
85 | break; | ||
86 | } | ||
87 | } else { | ||
88 | err = Z_STREAM_ERROR; | ||
89 | break; | ||
90 | } | ||
91 | |||
92 | /* Extra field */ | ||
93 | if (extsize > 0) { | ||
94 | if (fread(extra, 1, extsize, fpZip) == extsize) { | ||
95 | if (fwrite(extra, 1, extsize, fpOut) == extsize) { | ||
96 | offset += extsize; | ||
97 | } else { | ||
98 | err = Z_ERRNO; | ||
99 | break; | ||
100 | } | ||
101 | } else { | ||
102 | err = Z_ERRNO; | ||
103 | break; | ||
104 | } | ||
105 | } | ||
106 | |||
107 | /* Data */ | ||
108 | { | ||
109 | int dataSize = cpsize; | ||
110 | if (dataSize == 0) { | ||
111 | dataSize = uncpsize; | ||
112 | } | ||
113 | if (dataSize > 0) { | ||
114 | char* data = malloc(dataSize); | ||
115 | if (data != NULL) { | ||
116 | if ((int)fread(data, 1, dataSize, fpZip) == dataSize) { | ||
117 | if ((int)fwrite(data, 1, dataSize, fpOut) == dataSize) { | ||
118 | offset += dataSize; | ||
119 | totalBytes += dataSize; | ||
120 | } else { | ||
121 | err = Z_ERRNO; | ||
122 | } | ||
123 | } else { | ||
124 | err = Z_ERRNO; | ||
125 | } | ||
126 | free(data); | ||
127 | if (err != Z_OK) { | ||
128 | break; | ||
129 | } | ||
130 | } else { | ||
131 | err = Z_MEM_ERROR; | ||
132 | break; | ||
133 | } | ||
134 | } | ||
135 | } | ||
136 | |||
137 | /* Central directory entry */ | ||
138 | { | ||
139 | char header[46]; | ||
140 | char* comment = ""; | ||
141 | int comsize = (int) strlen(comment); | ||
142 | WRITE_32(header, 0x02014b50); | ||
143 | WRITE_16(header + 4, version); | ||
144 | WRITE_16(header + 6, version); | ||
145 | WRITE_16(header + 8, gpflag); | ||
146 | WRITE_16(header + 10, method); | ||
147 | WRITE_16(header + 12, filetime); | ||
148 | WRITE_16(header + 14, filedate); | ||
149 | WRITE_32(header + 16, crc); | ||
150 | WRITE_32(header + 20, cpsize); | ||
151 | WRITE_32(header + 24, uncpsize); | ||
152 | WRITE_16(header + 28, fnsize); | ||
153 | WRITE_16(header + 30, extsize); | ||
154 | WRITE_16(header + 32, comsize); | ||
155 | WRITE_16(header + 34, 0); /* disk # */ | ||
156 | WRITE_16(header + 36, 0); /* int attrb */ | ||
157 | WRITE_32(header + 38, 0); /* ext attrb */ | ||
158 | WRITE_32(header + 42, currentOffset); | ||
159 | /* Header */ | ||
160 | if (fwrite(header, 1, 46, fpOutCD) == 46) { | ||
161 | offsetCD += 46; | ||
162 | |||
163 | /* Filename */ | ||
164 | if (fnsize > 0) { | ||
165 | if (fwrite(filename, 1, fnsize, fpOutCD) == fnsize) { | ||
166 | offsetCD += fnsize; | ||
167 | } else { | ||
168 | err = Z_ERRNO; | ||
169 | break; | ||
170 | } | ||
171 | } else { | ||
172 | err = Z_STREAM_ERROR; | ||
173 | break; | ||
174 | } | ||
175 | |||
176 | /* Extra field */ | ||
177 | if (extsize > 0) { | ||
178 | if (fwrite(extra, 1, extsize, fpOutCD) == extsize) { | ||
179 | offsetCD += extsize; | ||
180 | } else { | ||
181 | err = Z_ERRNO; | ||
182 | break; | ||
183 | } | ||
184 | } | ||
185 | |||
186 | /* Comment field */ | ||
187 | if (comsize > 0) { | ||
188 | if ((int)fwrite(comment, 1, comsize, fpOutCD) == comsize) { | ||
189 | offsetCD += comsize; | ||
190 | } else { | ||
191 | err = Z_ERRNO; | ||
192 | break; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | |||
197 | } else { | ||
198 | err = Z_ERRNO; | ||
199 | break; | ||
200 | } | ||
201 | } | ||
202 | |||
203 | /* Success */ | ||
204 | entries++; | ||
205 | |||
206 | } else { | ||
207 | break; | ||
208 | } | ||
209 | } | ||
210 | |||
211 | /* Final central directory */ | ||
212 | { | ||
213 | int entriesZip = entries; | ||
214 | char header[22]; | ||
215 | char* comment = ""; // "ZIP File recovered by zlib/minizip/mztools"; | ||
216 | int comsize = (int) strlen(comment); | ||
217 | if (entriesZip > 0xffff) { | ||
218 | entriesZip = 0xffff; | ||
219 | } | ||
220 | WRITE_32(header, 0x06054b50); | ||
221 | WRITE_16(header + 4, 0); /* disk # */ | ||
222 | WRITE_16(header + 6, 0); /* disk # */ | ||
223 | WRITE_16(header + 8, entriesZip); /* hack */ | ||
224 | WRITE_16(header + 10, entriesZip); /* hack */ | ||
225 | WRITE_32(header + 12, offsetCD); /* size of CD */ | ||
226 | WRITE_32(header + 16, offset); /* offset to CD */ | ||
227 | WRITE_16(header + 20, comsize); /* comment */ | ||
228 | |||
229 | /* Header */ | ||
230 | if (fwrite(header, 1, 22, fpOutCD) == 22) { | ||
231 | |||
232 | /* Comment field */ | ||
233 | if (comsize > 0) { | ||
234 | if ((int)fwrite(comment, 1, comsize, fpOutCD) != comsize) { | ||
235 | err = Z_ERRNO; | ||
236 | } | ||
237 | } | ||
238 | |||
239 | } else { | ||
240 | err = Z_ERRNO; | ||
241 | } | ||
242 | } | ||
243 | |||
244 | /* Final merge (file + central directory) */ | ||
245 | fclose(fpOutCD); | ||
246 | if (err == Z_OK) { | ||
247 | fpOutCD = fopen(fileOutTmp, "rb"); | ||
248 | if (fpOutCD != NULL) { | ||
249 | int nRead; | ||
250 | char buffer[8192]; | ||
251 | while ( (nRead = fread(buffer, 1, sizeof(buffer), fpOutCD)) > 0) { | ||
252 | if ((int)fwrite(buffer, 1, nRead, fpOut) != nRead) { | ||
253 | err = Z_ERRNO; | ||
254 | break; | ||
255 | } | ||
256 | } | ||
257 | fclose(fpOutCD); | ||
258 | } | ||
259 | } | ||
260 | |||
261 | /* Close */ | ||
262 | fclose(fpZip); | ||
263 | fclose(fpOut); | ||
264 | |||
265 | /* Wipe temporary file */ | ||
266 | (void)remove(fileOutTmp); | ||
267 | |||
268 | /* Number of recovered entries */ | ||
269 | if (err == Z_OK) { | ||
270 | if (nRecovered != NULL) { | ||
271 | *nRecovered = entries; | ||
272 | } | ||
273 | if (bytesRecovered != NULL) { | ||
274 | *bytesRecovered = totalBytes; | ||
275 | } | ||
276 | } | ||
277 | } else { | ||
278 | err = Z_STREAM_ERROR; | ||
279 | } | ||
280 | return err; | ||
281 | } | ||
diff --git a/contrib/minizip/mztools.h b/contrib/minizip/mztools.h new file mode 100644 index 0000000..eee78dc --- /dev/null +++ b/contrib/minizip/mztools.h | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | Additional tools for Minizip | ||
3 | Code: Xavier Roche '2004 | ||
4 | License: Same as ZLIB (www.gzip.org) | ||
5 | */ | ||
6 | |||
7 | #ifndef _zip_tools_H | ||
8 | #define _zip_tools_H | ||
9 | |||
10 | #ifdef __cplusplus | ||
11 | extern "C" { | ||
12 | #endif | ||
13 | |||
14 | #ifndef _ZLIB_H | ||
15 | #include "zlib.h" | ||
16 | #endif | ||
17 | |||
18 | #include "unzip.h" | ||
19 | |||
20 | /* Repair a ZIP file (missing central directory) | ||
21 | file: file to recover | ||
22 | fileOut: output file after recovery | ||
23 | fileOutTmp: temporary file name used for recovery | ||
24 | */ | ||
25 | extern int ZEXPORT unzRepair(const char* file, | ||
26 | const char* fileOut, | ||
27 | const char* fileOutTmp, | ||
28 | uLong* nRecovered, | ||
29 | uLong* bytesRecovered); | ||
30 | |||
31 | #endif | ||
diff --git a/contrib/minizip/unzip.c b/contrib/minizip/unzip.c index f08f624..e804a2a 100644 --- a/contrib/minizip/unzip.c +++ b/contrib/minizip/unzip.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* unzip.c -- IO for uncompress .zip files using zlib | 1 | /* unzip.c -- IO for uncompress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01c, August 23th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | Read unzip.h for more info | 6 | Read unzip.h for more info |
7 | */ | 7 | */ |
@@ -88,7 +88,7 @@ woven in by Terry Thorsen 1/2003. | |||
88 | 88 | ||
89 | 89 | ||
90 | const char unz_copyright[] = | 90 | const char unz_copyright[] = |
91 | " unzip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; | 91 | " unzip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
92 | 92 | ||
93 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ | 93 | /* unz_file_info_interntal contain internal info about a file in zipfile*/ |
94 | typedef struct unz_file_info_internal_s | 94 | typedef struct unz_file_info_internal_s |
@@ -798,7 +798,8 @@ extern int ZEXPORT unzGoToNextFile (file) | |||
798 | s=(unz_s*)file; | 798 | s=(unz_s*)file; |
799 | if (!s->current_file_ok) | 799 | if (!s->current_file_ok) |
800 | return UNZ_END_OF_LIST_OF_FILE; | 800 | return UNZ_END_OF_LIST_OF_FILE; |
801 | if (s->num_file+1==s->gi.number_entry) | 801 | if (s->gi.number_entry != 0xffff) /* 2^16 files overflow hack */ |
802 | if (s->num_file+1==s->gi.number_entry) | ||
802 | return UNZ_END_OF_LIST_OF_FILE; | 803 | return UNZ_END_OF_LIST_OF_FILE; |
803 | 804 | ||
804 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + | 805 | s->pos_in_central_dir += SIZECENTRALDIRITEM + s->cur_file_info.size_filename + |
@@ -1244,9 +1245,15 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
1244 | 1245 | ||
1245 | pfile_in_zip_read_info->stream.avail_out = (uInt)len; | 1246 | pfile_in_zip_read_info->stream.avail_out = (uInt)len; |
1246 | 1247 | ||
1247 | if (len>pfile_in_zip_read_info->rest_read_uncompressed) | 1248 | if ((len>pfile_in_zip_read_info->rest_read_uncompressed) && |
1249 | (!(pfile_in_zip_read_info->raw))) | ||
1248 | pfile_in_zip_read_info->stream.avail_out = | 1250 | pfile_in_zip_read_info->stream.avail_out = |
1249 | (uInt)pfile_in_zip_read_info->rest_read_uncompressed; | 1251 | (uInt)pfile_in_zip_read_info->rest_read_uncompressed; |
1252 | |||
1253 | if ((len>pfile_in_zip_read_info->rest_read_compressed) && | ||
1254 | (pfile_in_zip_read_info->raw)) | ||
1255 | pfile_in_zip_read_info->stream.avail_out = | ||
1256 | (uInt)pfile_in_zip_read_info->rest_read_compressed; | ||
1250 | 1257 | ||
1251 | while (pfile_in_zip_read_info->stream.avail_out>0) | 1258 | while (pfile_in_zip_read_info->stream.avail_out>0) |
1252 | { | 1259 | { |
@@ -1339,6 +1346,9 @@ extern int ZEXPORT unzReadCurrentFile (file, buf, len) | |||
1339 | */ | 1346 | */ |
1340 | err=inflate(&pfile_in_zip_read_info->stream,flush); | 1347 | err=inflate(&pfile_in_zip_read_info->stream,flush); |
1341 | 1348 | ||
1349 | if ((err>=0) && (pfile_in_zip_read_info->stream.msg!=NULL)) | ||
1350 | err = Z_DATA_ERROR; | ||
1351 | |||
1342 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; | 1352 | uTotalOutAfter = pfile_in_zip_read_info->stream.total_out; |
1343 | uOutThis = uTotalOutAfter-uTotalOutBefore; | 1353 | uOutThis = uTotalOutAfter-uTotalOutBefore; |
1344 | 1354 | ||
@@ -1461,7 +1471,7 @@ extern int ZEXPORT unzGetLocalExtrafield (file,buf,len) | |||
1461 | 1471 | ||
1462 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, | 1472 | if (ZREAD(pfile_in_zip_read_info->z_filefunc, |
1463 | pfile_in_zip_read_info->filestream, | 1473 | pfile_in_zip_read_info->filestream, |
1464 | buf,size_to_read)!=size_to_read) | 1474 | buf,read_now)!=read_now) |
1465 | return UNZ_ERRNO; | 1475 | return UNZ_ERRNO; |
1466 | 1476 | ||
1467 | return (int)read_now; | 1477 | return (int)read_now; |
@@ -1544,3 +1554,40 @@ extern int ZEXPORT unzGetGlobalComment (file, szComment, uSizeBuf) | |||
1544 | *(szComment+s->gi.size_comment)='\0'; | 1554 | *(szComment+s->gi.size_comment)='\0'; |
1545 | return (int)uReadThis; | 1555 | return (int)uReadThis; |
1546 | } | 1556 | } |
1557 | |||
1558 | /* Additions by RX '2004 */ | ||
1559 | extern uLong ZEXPORT unzGetOffset (file) | ||
1560 | unzFile file; | ||
1561 | { | ||
1562 | unz_s* s; | ||
1563 | |||
1564 | if (file==NULL) | ||
1565 | return UNZ_PARAMERROR; | ||
1566 | s=(unz_s*)file; | ||
1567 | if (!s->current_file_ok) | ||
1568 | return 0; | ||
1569 | if (s->gi.number_entry != 0 && s->gi.number_entry != 0xffff) | ||
1570 | if (s->num_file==s->gi.number_entry) | ||
1571 | return 0; | ||
1572 | return s->pos_in_central_dir; | ||
1573 | } | ||
1574 | |||
1575 | extern int ZEXPORT unzSetOffset (file, pos) | ||
1576 | unzFile file; | ||
1577 | uLong pos; | ||
1578 | { | ||
1579 | unz_s* s; | ||
1580 | int err; | ||
1581 | |||
1582 | if (file==NULL) | ||
1583 | return UNZ_PARAMERROR; | ||
1584 | s=(unz_s*)file; | ||
1585 | |||
1586 | s->pos_in_central_dir = pos; | ||
1587 | s->num_file = s->gi.number_entry; /* hack */ | ||
1588 | err = unzlocal_GetCurrentFileInfoInternal(file,&s->cur_file_info, | ||
1589 | &s->cur_file_info_internal, | ||
1590 | NULL,0,NULL,0,NULL,0); | ||
1591 | s->current_file_ok = (err == UNZ_OK); | ||
1592 | return err; | ||
1593 | } | ||
diff --git a/contrib/minizip/unzip.h b/contrib/minizip/unzip.h index 4e50979..0c7c6f1 100644 --- a/contrib/minizip/unzip.h +++ b/contrib/minizip/unzip.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* unzip.h -- IO for uncompress .zip files using zlib | 1 | /* unzip.h -- IO for uncompress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g | 6 | This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g |
7 | WinZip, InfoZip tools and compatible. | 7 | WinZip, InfoZip tools and compatible. |
@@ -335,6 +335,16 @@ extern int ZEXPORT unzGetLocalExtrafield OF((unzFile file, | |||
335 | the error code | 335 | the error code |
336 | */ | 336 | */ |
337 | 337 | ||
338 | /***************************************************************************/ | ||
339 | |||
340 | /* Get the current file offset */ | ||
341 | extern uLong ZEXPORT unzGetOffset (unzFile file); | ||
342 | |||
343 | /* Set the current file offset */ | ||
344 | extern int ZEXPORT unzSetOffset (unzFile file, uLong pos); | ||
345 | |||
346 | |||
347 | |||
338 | #ifdef __cplusplus | 348 | #ifdef __cplusplus |
339 | } | 349 | } |
340 | #endif | 350 | #endif |
diff --git a/contrib/minizip/zip.c b/contrib/minizip/zip.c index 1a713e5..ce1444c 100644 --- a/contrib/minizip/zip.c +++ b/contrib/minizip/zip.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* zip.c -- IO on .zip files using zlib | 1 | /* zip.c -- IO on .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | Read zip.h for more info | 6 | Read zip.h for more info |
7 | */ | 7 | */ |
@@ -77,7 +77,7 @@ | |||
77 | #endif | 77 | #endif |
78 | #endif | 78 | #endif |
79 | const char zip_copyright[] = | 79 | const char zip_copyright[] = |
80 | " zip 1.00 Copyright 1998-2003 Gilles Vollant - http://www.winimage.com/zLibDll"; | 80 | " zip 1.01 Copyright 1998-2004 Gilles Vollant - http://www.winimage.com/zLibDll"; |
81 | 81 | ||
82 | 82 | ||
83 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) | 83 | #define SIZEDATA_INDATABLOCK (4096-(4*4)) |
@@ -265,10 +265,19 @@ local int ziplocal_putValue (pzlib_filefunc_def, filestream, x, nbByte) | |||
265 | { | 265 | { |
266 | unsigned char buf[4]; | 266 | unsigned char buf[4]; |
267 | int n; | 267 | int n; |
268 | for (n = 0; n < nbByte; n++) { | 268 | for (n = 0; n < nbByte; n++) |
269 | { | ||
269 | buf[n] = (unsigned char)(x & 0xff); | 270 | buf[n] = (unsigned char)(x & 0xff); |
270 | x >>= 8; | 271 | x >>= 8; |
271 | } | 272 | } |
273 | if (x != 0) | ||
274 | { /* data overflow - hack for ZIP64 (X Roche) */ | ||
275 | for (n = 0; n < nbByte; n++) | ||
276 | { | ||
277 | buf[n] = 0xff; | ||
278 | } | ||
279 | } | ||
280 | |||
272 | if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) | 281 | if (ZWRITE(*pzlib_filefunc_def,filestream,buf,nbByte)!=(uLong)nbByte) |
273 | return ZIP_ERRNO; | 282 | return ZIP_ERRNO; |
274 | else | 283 | else |
@@ -287,7 +296,16 @@ local void ziplocal_putValue_inmemory (dest, x, nbByte) | |||
287 | buf[n] = (unsigned char)(x & 0xff); | 296 | buf[n] = (unsigned char)(x & 0xff); |
288 | x >>= 8; | 297 | x >>= 8; |
289 | } | 298 | } |
299 | |||
300 | if (x != 0) | ||
301 | { /* data overflow - hack for ZIP64 */ | ||
302 | for (n = 0; n < nbByte; n++) | ||
303 | { | ||
304 | buf[n] = 0xff; | ||
305 | } | ||
306 | } | ||
290 | } | 307 | } |
308 | |||
291 | /****************************************************************************/ | 309 | /****************************************************************************/ |
292 | 310 | ||
293 | 311 | ||
diff --git a/contrib/minizip/zip.h b/contrib/minizip/zip.h index c37ea21..d5112c4 100644 --- a/contrib/minizip/zip.h +++ b/contrib/minizip/zip.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /* zip.h -- IO for compress .zip files using zlib | 1 | /* zip.h -- IO for compress .zip files using zlib |
2 | Version 1.00, September 10th, 2003 | 2 | Version 1.01, May 8th, 2004 |
3 | 3 | ||
4 | Copyright (C) 1998-2003 Gilles Vollant | 4 | Copyright (C) 1998-2004 Gilles Vollant |
5 | 5 | ||
6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g | 6 | This unzip package allow creates .ZIP file, compatible with PKZip 2.04g |
7 | WinZip, InfoZip tools and compatible. | 7 | WinZip, InfoZip tools and compatible. |
@@ -212,7 +212,6 @@ extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); | |||
212 | Close the current file in the zipfile | 212 | Close the current file in the zipfile |
213 | */ | 213 | */ |
214 | 214 | ||
215 | |||
216 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, | 215 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, |
217 | uLong uncompressed_size, | 216 | uLong uncompressed_size, |
218 | uLong crc32)); | 217 | uLong crc32)); |
diff --git a/contrib/pascal/zlibpas.pas b/contrib/pascal/zlibpas.pas index 6d5ebe0..94103d2 100644 --- a/contrib/pascal/zlibpas.pas +++ b/contrib/pascal/zlibpas.pas | |||
@@ -10,7 +10,7 @@ unit zlibpas; | |||
10 | interface | 10 | interface |
11 | 11 | ||
12 | const | 12 | const |
13 | ZLIB_VERSION = '1.2.1'; | 13 | ZLIB_VERSION = '1.2.2'; |
14 | 14 | ||
15 | type | 15 | type |
16 | alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; | 16 | alloc_func = function(opaque: Pointer; items, size: Integer): Pointer; |
diff --git a/contrib/untgz/untgz.c b/contrib/untgz/untgz.c index d748b69..3a30768 100644 --- a/contrib/untgz/untgz.c +++ b/contrib/untgz/untgz.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * untgz.c -- Display contents and extract files from a gzip'd TAR file | 2 | * untgz.c -- Display contents and extract files from a gzip'd TAR file |
3 | * | 3 | * |
4 | * written by "Pedro A. Aranda Guti\irrez" <paag@tid.es> | 4 | * written by Pedro A. Aranda Gutierrez <paag@tid.es> |
5 | * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org> | 5 | * adaptation to Unix by Jean-loup Gailly <jloup@gzip.org> |
6 | * various fixes by Cosmin Truta <cosmint@cs.ubbcluj.ro> | 6 | * various fixes by Cosmin Truta <cosmint@cs.ubbcluj.ro> |
7 | */ | 7 | */ |
@@ -15,10 +15,10 @@ | |||
15 | #include "zlib.h" | 15 | #include "zlib.h" |
16 | 16 | ||
17 | #ifdef unix | 17 | #ifdef unix |
18 | # include <unistd.h> | 18 | # include <unistd.h> |
19 | #else | 19 | #else |
20 | # include <direct.h> | 20 | # include <direct.h> |
21 | # include <io.h> | 21 | # include <io.h> |
22 | #endif | 22 | #endif |
23 | 23 | ||
24 | #ifdef WIN32 | 24 | #ifdef WIN32 |
@@ -28,8 +28,9 @@ | |||
28 | # endif | 28 | # endif |
29 | # define mkdir(dirname,mode) _mkdir(dirname) | 29 | # define mkdir(dirname,mode) _mkdir(dirname) |
30 | # ifdef _MSC_VER | 30 | # ifdef _MSC_VER |
31 | # define strdup(str) _strdup(str) | ||
32 | # define access(path,mode) _access(path,mode) | 31 | # define access(path,mode) _access(path,mode) |
32 | # define chmod(path,mode) _chmod(path,mode) | ||
33 | # define strdup(str) _strdup(str) | ||
33 | # endif | 34 | # endif |
34 | #else | 35 | #else |
35 | # include <utime.h> | 36 | # include <utime.h> |
@@ -48,7 +49,21 @@ | |||
48 | #define FIFOTYPE '6' /* FIFO special */ | 49 | #define FIFOTYPE '6' /* FIFO special */ |
49 | #define CONTTYPE '7' /* reserved */ | 50 | #define CONTTYPE '7' /* reserved */ |
50 | 51 | ||
51 | #define BLOCKSIZE 512 | 52 | /* GNU tar extensions */ |
53 | |||
54 | #define GNUTYPE_DUMPDIR 'D' /* file names from dumped directory */ | ||
55 | #define GNUTYPE_LONGLINK 'K' /* long link name */ | ||
56 | #define GNUTYPE_LONGNAME 'L' /* long file name */ | ||
57 | #define GNUTYPE_MULTIVOL 'M' /* continuation of file from another volume */ | ||
58 | #define GNUTYPE_NAMES 'N' /* file name that does not fit into main hdr */ | ||
59 | #define GNUTYPE_SPARSE 'S' /* sparse file */ | ||
60 | #define GNUTYPE_VOLHDR 'V' /* tape/volume header */ | ||
61 | |||
62 | |||
63 | /* tar header */ | ||
64 | |||
65 | #define BLOCKSIZE 512 | ||
66 | #define SHORTNAMESIZE 100 | ||
52 | 67 | ||
53 | struct tar_header | 68 | struct tar_header |
54 | { /* byte offset */ | 69 | { /* byte offset */ |
@@ -71,11 +86,20 @@ struct tar_header | |||
71 | /* 500 */ | 86 | /* 500 */ |
72 | }; | 87 | }; |
73 | 88 | ||
74 | union tar_buffer { | 89 | union tar_buffer |
90 | { | ||
75 | char buffer[BLOCKSIZE]; | 91 | char buffer[BLOCKSIZE]; |
76 | struct tar_header header; | 92 | struct tar_header header; |
77 | }; | 93 | }; |
78 | 94 | ||
95 | struct attr_item | ||
96 | { | ||
97 | struct attr_item *next; | ||
98 | char *fname; | ||
99 | int mode; | ||
100 | time_t time; | ||
101 | }; | ||
102 | |||
79 | enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; | 103 | enum { TGZ_EXTRACT, TGZ_LIST, TGZ_INVALID }; |
80 | 104 | ||
81 | char *TGZfname OF((const char *)); | 105 | char *TGZfname OF((const char *)); |
@@ -84,6 +108,9 @@ void TGZnotfound OF((const char *)); | |||
84 | int getoct OF((char *, int)); | 108 | int getoct OF((char *, int)); |
85 | char *strtime OF((time_t *)); | 109 | char *strtime OF((time_t *)); |
86 | int setfiletime OF((char *, time_t)); | 110 | int setfiletime OF((char *, time_t)); |
111 | void push_attr OF((struct attr_item **, char *, int, time_t)); | ||
112 | void restore_attr OF((struct attr_item **)); | ||
113 | |||
87 | int ExprMatch OF((char *, char *)); | 114 | int ExprMatch OF((char *, char *)); |
88 | 115 | ||
89 | int makedir OF((char *)); | 116 | int makedir OF((char *)); |
@@ -221,7 +248,42 @@ int setfiletime (char *fname,time_t ftime) | |||
221 | } | 248 | } |
222 | 249 | ||
223 | 250 | ||
224 | /* regular expression matching */ | 251 | /* push file attributes */ |
252 | |||
253 | void push_attr(struct attr_item **list,char *fname,int mode,time_t time) | ||
254 | { | ||
255 | struct attr_item *item; | ||
256 | |||
257 | item = (struct attr_item *)malloc(sizeof(struct attr_item)); | ||
258 | if (item == NULL) | ||
259 | error("Out of memory"); | ||
260 | item->fname = strdup(fname); | ||
261 | item->mode = mode; | ||
262 | item->time = time; | ||
263 | item->next = *list; | ||
264 | *list = item; | ||
265 | } | ||
266 | |||
267 | |||
268 | /* restore file attributes */ | ||
269 | |||
270 | void restore_attr(struct attr_item **list) | ||
271 | { | ||
272 | struct attr_item *item, *prev; | ||
273 | |||
274 | for (item = *list; item != NULL; ) | ||
275 | { | ||
276 | setfiletime(item->fname,item->time); | ||
277 | chmod(item->fname,item->mode); | ||
278 | prev = item; | ||
279 | item = item->next; | ||
280 | free(prev); | ||
281 | } | ||
282 | *list = NULL; | ||
283 | } | ||
284 | |||
285 | |||
286 | /* match regular expression */ | ||
225 | 287 | ||
226 | #define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) | 288 | #define ISSPECIAL(c) (((c) == '*') || ((c) == '/')) |
227 | 289 | ||
@@ -332,6 +394,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
332 | char fname[BLOCKSIZE]; | 394 | char fname[BLOCKSIZE]; |
333 | int tarmode; | 395 | int tarmode; |
334 | time_t tartime; | 396 | time_t tartime; |
397 | struct attr_item *attributes = NULL; | ||
335 | 398 | ||
336 | if (action == TGZ_LIST) | 399 | if (action == TGZ_LIST) |
337 | printf(" date time size file\n" | 400 | printf(" date time size file\n" |
@@ -354,14 +417,15 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
354 | /* | 417 | /* |
355 | * If we have to get a tar header | 418 | * If we have to get a tar header |
356 | */ | 419 | */ |
357 | if (getheader == 1) | 420 | if (getheader >= 1) |
358 | { | 421 | { |
359 | /* | 422 | /* |
360 | * if we met the end of the tar | 423 | * if we met the end of the tar |
361 | * or the end-of-tar block, | 424 | * or the end-of-tar block, |
362 | * we are done | 425 | * we are done |
363 | */ | 426 | */ |
364 | if ((len == 0) || (buffer.header.name[0] == 0)) break; | 427 | if (len == 0 || buffer.header.name[0] == 0) |
428 | break; | ||
365 | 429 | ||
366 | tarmode = getoct(buffer.header.mode,8); | 430 | tarmode = getoct(buffer.header.mode,8); |
367 | tartime = (time_t)getoct(buffer.header.mtime,12); | 431 | tartime = (time_t)getoct(buffer.header.mtime,12); |
@@ -371,8 +435,25 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
371 | action = TGZ_INVALID; | 435 | action = TGZ_INVALID; |
372 | } | 436 | } |
373 | 437 | ||
374 | strcpy(fname,buffer.header.name); | 438 | if (getheader == 1) |
439 | { | ||
440 | strncpy(fname,buffer.header.name,SHORTNAMESIZE); | ||
441 | if (fname[SHORTNAMESIZE-1] != 0) | ||
442 | fname[SHORTNAMESIZE] = 0; | ||
443 | } | ||
444 | else | ||
445 | { | ||
446 | /* | ||
447 | * The file name is longer than SHORTNAMESIZE | ||
448 | */ | ||
449 | if (strncmp(fname,buffer.header.name,SHORTNAMESIZE-1) != 0) | ||
450 | error("bad long name"); | ||
451 | getheader = 1; | ||
452 | } | ||
375 | 453 | ||
454 | /* | ||
455 | * Act according to the type flag | ||
456 | */ | ||
376 | switch (buffer.header.typeflag) | 457 | switch (buffer.header.typeflag) |
377 | { | 458 | { |
378 | case DIRTYPE: | 459 | case DIRTYPE: |
@@ -381,7 +462,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
381 | if (action == TGZ_EXTRACT) | 462 | if (action == TGZ_EXTRACT) |
382 | { | 463 | { |
383 | makedir(fname); | 464 | makedir(fname); |
384 | setfiletime(fname,tartime); | 465 | push_attr(&attributes,fname,tarmode,tartime); |
385 | } | 466 | } |
386 | break; | 467 | break; |
387 | case REGTYPE: | 468 | case REGTYPE: |
@@ -419,6 +500,24 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
419 | } | 500 | } |
420 | getheader = 0; | 501 | getheader = 0; |
421 | break; | 502 | break; |
503 | case GNUTYPE_LONGLINK: | ||
504 | case GNUTYPE_LONGNAME: | ||
505 | remaining = getoct(buffer.header.size,12); | ||
506 | if (remaining < 0 || remaining >= BLOCKSIZE) | ||
507 | { | ||
508 | action = TGZ_INVALID; | ||
509 | break; | ||
510 | } | ||
511 | len = gzread(in, fname, BLOCKSIZE); | ||
512 | if (len < 0) | ||
513 | error(gzerror(in, &err)); | ||
514 | if (fname[BLOCKSIZE-1] != 0 || (int)strlen(fname) > remaining) | ||
515 | { | ||
516 | action = TGZ_INVALID; | ||
517 | break; | ||
518 | } | ||
519 | getheader = 2; | ||
520 | break; | ||
422 | default: | 521 | default: |
423 | if (action == TGZ_LIST) | 522 | if (action == TGZ_LIST) |
424 | printf(" %s <---> %s\n",strtime(&tartime),fname); | 523 | printf(" %s <---> %s\n",strtime(&tartime),fname); |
@@ -433,7 +532,8 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
433 | { | 532 | { |
434 | if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) | 533 | if (fwrite(&buffer,sizeof(char),bytes,outfile) != bytes) |
435 | { | 534 | { |
436 | fprintf(stderr,"%s: Error writing %s -- skipping\n",prog,fname); | 535 | fprintf(stderr, |
536 | "%s: Error writing %s -- skipping\n",prog,fname); | ||
437 | fclose(outfile); | 537 | fclose(outfile); |
438 | outfile = NULL; | 538 | outfile = NULL; |
439 | remove(fname); | 539 | remove(fname); |
@@ -450,7 +550,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
450 | fclose(outfile); | 550 | fclose(outfile); |
451 | outfile = NULL; | 551 | outfile = NULL; |
452 | if (action != TGZ_INVALID) | 552 | if (action != TGZ_INVALID) |
453 | setfiletime(fname,tartime); | 553 | push_attr(&attributes,fname,tarmode,tartime); |
454 | } | 554 | } |
455 | } | 555 | } |
456 | 556 | ||
@@ -464,6 +564,11 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
464 | } | 564 | } |
465 | } | 565 | } |
466 | 566 | ||
567 | /* | ||
568 | * Restore file modes and time stamps | ||
569 | */ | ||
570 | restore_attr(&attributes); | ||
571 | |||
467 | if (gzclose(in) != Z_OK) | 572 | if (gzclose(in) != Z_OK) |
468 | error("failed gzclose"); | 573 | error("failed gzclose"); |
469 | 574 | ||
@@ -475,7 +580,7 @@ int tar (gzFile in,int action,int arg,int argc,char **argv) | |||
475 | 580 | ||
476 | void help(int exitval) | 581 | void help(int exitval) |
477 | { | 582 | { |
478 | printf("untgz version 0.2\n" | 583 | printf("untgz version 0.2.1\n" |
479 | " using zlib version %s\n\n", | 584 | " using zlib version %s\n\n", |
480 | zlibVersion()); | 585 | zlibVersion()); |
481 | printf("Usage: untgz file.tgz extract all files\n" | 586 | printf("Usage: untgz file.tgz extract all files\n" |
diff --git a/contrib/vstudio/vc7/zlib.rc b/contrib/vstudio/vc7/zlib.rc index 6c51679..2eb7c6b 100644 --- a/contrib/vstudio/vc7/zlib.rc +++ b/contrib/vstudio/vc7/zlib.rc | |||
@@ -2,8 +2,8 @@ | |||
2 | 2 | ||
3 | #define IDR_VERSION1 1 | 3 | #define IDR_VERSION1 1 |
4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE | 4 | IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE |
5 | FILEVERSION 1,2,1,0 | 5 | FILEVERSION 1,2,1,2 |
6 | PRODUCTVERSION 1,2,1,0 | 6 | PRODUCTVERSION 1,2,1,2 |
7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK | 7 | FILEFLAGSMASK VS_FFI_FILEFLAGSMASK |
8 | FILEFLAGS 0 | 8 | FILEFLAGS 0 |
9 | FILEOS VOS_DOS_WINDOWS32 | 9 | FILEOS VOS_DOS_WINDOWS32 |
@@ -17,7 +17,7 @@ BEGIN | |||
17 | 17 | ||
18 | BEGIN | 18 | BEGIN |
19 | VALUE "FileDescription", "zlib data compression library\0" | 19 | VALUE "FileDescription", "zlib data compression library\0" |
20 | VALUE "FileVersion", "1.2.1.0\0" | 20 | VALUE "FileVersion", "1.2.1.2\0" |
21 | VALUE "InternalName", "zlib\0" | 21 | VALUE "InternalName", "zlib\0" |
22 | VALUE "OriginalFilename", "zlib.dll\0" | 22 | VALUE "OriginalFilename", "zlib.dll\0" |
23 | VALUE "ProductName", "ZLib.DLL\0" | 23 | VALUE "ProductName", "ZLib.DLL\0" |