1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include <exec/exec.h>
29 #include <proto/exec.h>
32 #include <SDI_compiler.h>
33 #include "bz2.library_rev.h"
35 #define LIBNAME "bz2.library"
36 const char USED verstag
[] = VERSTAG
;
42 struct ExecBase
*SysBase
;
45 struct Library libNode
;
50 int malloc_init(void);
51 void malloc_exit(void);
54 static AROS_UFP3(struct BZ2Base
*, LibInit
,
55 AROS_UFPA(struct BZ2Base
*, libBase
, D0
),
56 AROS_UFPA(BPTR
, seglist
, A0
),
57 AROS_UFPA(struct ExecBase
*, exec_base
, A6
)
59 static AROS_LD1(struct BZ2Base
*, LibOpen
,
60 AROS_LPA(ULONG
, version
, D0
),
61 struct BZ2Base
*, libBase
, 1, BZlib
63 static AROS_LD0(BPTR
, LibClose
,
64 struct BZ2Base
*, libBase
, 2, BZlib
66 static AROS_LD0(BPTR
, LibExpunge
,
67 struct BZ2Base
*, libBase
, 3, BZlib
69 static AROS_LD0(APTR
, LibReserved
,
70 struct BZ2Base
*, libBase
, 4, BZlib
72 static AROS_LD0(const char *, BZlibVersion
,
73 struct BZ2Base
*, libBase
, 5, BZlib
75 static AROS_LD4(LONG
, CompressInit
,
76 AROS_LPA(bz_stream
*, strm
, A0
),
77 AROS_LPA(LONG
, blockSize100k
, D0
),
78 AROS_LPA(LONG
, verbosity
, D1
),
79 AROS_LPA(LONG
, workFactor
, D2
),
80 struct BZ2Base
*, libBase
, 6, BZlib
82 static AROS_LD2(LONG
, Compress
,
83 AROS_LPA(bz_stream
*, strm
, A0
),
84 AROS_LPA(LONG
, action
, D0
),
85 struct BZ2Base
*, libBase
, 7, BZlib
87 static AROS_LD1(LONG
, CompressEnd
,
88 AROS_LPA(bz_stream
*, strm
, A0
),
89 struct BZ2Base
*, libBase
, 8, BZlib
91 static AROS_LD3(LONG
, DecompressInit
,
92 AROS_LPA(bz_stream
*, strm
, A0
),
93 AROS_LPA(LONG
, verbosity
, D0
),
94 AROS_LPA(LONG
, small
, D1
),
95 struct BZ2Base
*, libBase
, 9, BZlib
97 static AROS_LD1(LONG
, Decompress
,
98 AROS_LPA(bz_stream
*, strm
, A0
),
99 struct BZ2Base
*, libBase
, 10, BZlib
101 static AROS_LD1(LONG
, DecompressEnd
,
102 AROS_LPA(bz_stream
*, strm
, A0
),
103 struct BZ2Base
*, libBase
, 11, BZlib
105 static AROS_LD7(LONG
, BuffToBuffCompress
,
106 AROS_LPA(APTR
, dest
, A0
),
107 AROS_LPA(ULONG
*, destLen
, A1
),
108 AROS_LPA(APTR
, source
, A2
),
109 AROS_LPA(ULONG
, sourceLen
, D0
),
110 AROS_LPA(LONG
, blockSize100k
, D1
),
111 AROS_LPA(LONG
, verbosity
, D2
),
112 AROS_LPA(LONG
, workFactor
, D3
),
113 struct BZ2Base
*, libBase
, 12, BZlib
115 static AROS_LD6(LONG
, BuffToBuffDecompress
,
116 AROS_LPA(APTR
, dest
, A0
),
117 AROS_LPA(ULONG
*, destLen
, A1
),
118 AROS_LPA(APTR
, source
, A2
),
119 AROS_LPA(ULONG
, sourceLen
, D0
),
120 AROS_LPA(LONG
, small
, D1
),
121 AROS_LPA(LONG
, verbosity
, D2
),
122 struct BZ2Base
*, libBase
, 13, BZlib
125 static struct BZ2Base
*LibInit (REG(d0
, struct BZ2Base
*libBase
), REG(a0
, BPTR seglist
),
126 REG(a6
, struct ExecBase
*exec_base
));
127 static struct BZ2Base
*BZlib_LibOpen (REG(a6
, struct BZ2Base
*libBase
), REG(d0
, ULONG version
));
128 static BPTR
BZlib_LibClose (REG(a6
, struct BZ2Base
*libBase
));
129 static BPTR
BZlib_LibExpunge (REG(a6
, struct BZ2Base
*libBase
));
130 static APTR
BZlib_LibReserved (REG(a6
, struct BZ2Base
*libBase
));
131 static const char *BZlib_BZlibVersion(void);
132 static LONG
BZlib_CompressInit(REG(a0
, bz_stream
*strm
), REG(d0
, LONG blockSize100k
),
133 REG(d1
, LONG verbosity
), REG(d2
, LONG workFactor
));
134 static LONG
BZlib_Compress(REG(a0
, bz_stream
*strm
), REG(d0
, LONG action
));
135 static LONG
BZlib_CompressEnd(REG(a0
, bz_stream
*strm
));
136 static LONG
BZlib_DecompressInit(REG(a0
, bz_stream
*strm
), REG(d0
, LONG verbosity
),
137 REG(d1
, LONG small
));
138 static LONG
BZlib_Decompress(REG(a0
, bz_stream
*strm
));
139 static LONG
BZlib_DecompressEnd(REG(a0
, bz_stream
*strm
));
140 static LONG
BZlib_BuffToBuffCompress(REG(a0
, APTR dest
), REG(a1
, ULONG
*destLen
),
141 REG(a2
, APTR source
), REG(d0
, ULONG sourceLen
), REG(d1
, LONG blockSize100k
),
142 REG(d2
, LONG verbosity
), REG(d3
, LONG workFactor
));
143 static LONG
BZlib_BuffToBuffDecompress(REG(a0
, APTR dest
), REG(a1
, ULONG
*destLen
),
144 REG(a2
, APTR source
), REG(d0
, ULONG sourceLen
), REG(d1
, LONG small
),
145 REG(d2
, LONG verbosity
));
150 #define LIB_ENTRY(a,b) AROS_SLIB_ENTRY(a, BZlib, b)
152 #define LIB_ENTRY(a,b) AROS_SLIB_ENTRY(a, BZlib)
155 #define LIB_ENTRY(a,b) BZlib_##a
158 const CONST_APTR LibVectors
[] = {
159 (APTR
)LIB_ENTRY(LibOpen
, 1),
160 (APTR
)LIB_ENTRY(LibClose
, 2),
161 (APTR
)LIB_ENTRY(LibExpunge
, 3),
162 (APTR
)LIB_ENTRY(LibReserved
, 4),
163 (APTR
)LIB_ENTRY(BZlibVersion
, 5),
164 (APTR
)LIB_ENTRY(CompressInit
, 6),
165 (APTR
)LIB_ENTRY(Compress
, 7),
166 (APTR
)LIB_ENTRY(CompressEnd
, 8),
167 (APTR
)LIB_ENTRY(DecompressInit
, 9),
168 (APTR
)LIB_ENTRY(Decompress
, 10),
169 (APTR
)LIB_ENTRY(DecompressEnd
, 11),
170 (APTR
)LIB_ENTRY(BuffToBuffCompress
, 12),
171 (APTR
)LIB_ENTRY(BuffToBuffDecompress
, 13),
175 const IPTR LibInitTab
[] = {
176 sizeof(struct BZ2Base
),
182 CONST
struct Resident USED lib_res
= {
184 (struct Resident
*)&lib_res
,
185 (APTR
)(&lib_res
+ 1),
196 static AROS_UFH3(struct BZ2Base
*, LibInit
,
197 AROS_UFHA(struct BZ2Base
*, libBase
, D0
),
198 AROS_UFHA(BPTR
, seglist
, A0
),
199 AROS_UFHA(struct ExecBase
*, exec_base
, A6
)
204 static struct BZ2Base
*LibInit (REG(d0
, struct BZ2Base
*libBase
), REG(a0
, BPTR seglist
),
205 REG(a6
, struct ExecBase
*exec_base
))
208 libBase
->libNode
.lib_Node
.ln_Type
= NT_LIBRARY
;
209 libBase
->libNode
.lib_Node
.ln_Pri
= 0;
210 libBase
->libNode
.lib_Node
.ln_Name
= LIBNAME
;
211 libBase
->libNode
.lib_Flags
= LIBF_SUMUSED
|LIBF_CHANGED
;
212 libBase
->libNode
.lib_Version
= VERSION
;
213 libBase
->libNode
.lib_Revision
= REVISION
;
214 libBase
->libNode
.lib_IdString
= VSTRING
;
217 libBase
->seglist
= seglist
;
223 DeleteLibrary((struct Library
*)libBase
);
232 static AROS_LH1(struct BZ2Base
*, LibOpen
,
233 AROS_LHA(ULONG
, version
, D0
),
234 struct BZ2Base
*, libBase
, 1, BZlib
239 static struct BZ2Base
*BZlib_LibOpen (REG(a6
, struct BZ2Base
*libBase
), REG(d0
, ULONG version
)) {
241 libBase
->libNode
.lib_OpenCnt
++;
242 libBase
->libNode
.lib_Flags
&= ~LIBF_DELEXP
;
250 static AROS_LH0(BPTR
, LibClose
,
251 struct BZ2Base
*, libBase
, 2, BZlib
256 static BPTR
BZlib_LibClose (REG(a6
, struct BZ2Base
*libBase
)) {
258 libBase
->libNode
.lib_OpenCnt
--;
266 static AROS_LH0(BPTR
, LibExpunge
,
267 struct BZ2Base
*, libBase
, 3, BZlib
272 static BPTR
BZlib_LibExpunge (REG(a6
, struct BZ2Base
*libBase
)) {
276 if (libBase
->libNode
.lib_OpenCnt
> 0) {
277 libBase
->libNode
.lib_Flags
|= LIBF_DELEXP
;
281 Remove(&libBase
->libNode
.lib_Node
);
283 result
= libBase
->seglist
;
287 DeleteLibrary((struct Library
*)libBase
);
296 static AROS_LH0(APTR
, LibReserved
,
297 struct BZ2Base
*, libBase
, 4, BZlib
305 static APTR
BZlib_LibReserved (REG(a6
, struct BZ2Base
*libBase
)) {
311 static AROS_LH0(const char *, BZlibVersion
,
312 struct BZ2Base
*, libBase
, 5, BZlib
317 static const char *BZlib_BZlibVersion(void) {
319 return BZ2_bzlibVersion();
326 static AROS_LH4(LONG
, CompressInit
,
327 AROS_LHA(bz_stream
*, strm
, A0
),
328 AROS_LHA(LONG
, blockSize100k
, D0
),
329 AROS_LHA(LONG
, verbosity
, D1
),
330 AROS_LHA(LONG
, workFactor
, D2
),
331 struct BZ2Base
*, libBase
, 6, BZlib
336 static LONG
BZlib_CompressInit(REG(a0
, bz_stream
*strm
), REG(d0
, LONG blockSize100k
),
337 REG(d1
, LONG verbosity
), REG(d2
, LONG workFactor
))
340 return BZ2_bzCompressInit(strm
, blockSize100k
, verbosity
, workFactor
);
347 static AROS_LH2(LONG
, Compress
,
348 AROS_LHA(bz_stream
*, strm
, A0
),
349 AROS_LHA(LONG
, action
, D0
),
350 struct BZ2Base
*, libBase
, 7, BZlib
355 static LONG
BZlib_Compress(REG(a0
, bz_stream
*strm
), REG(d0
, LONG action
)) {
357 return BZ2_bzCompress(strm
, action
);
364 static AROS_LH1(LONG
, CompressEnd
,
365 AROS_LHA(bz_stream
*, strm
, A0
),
366 struct BZ2Base
*, libBase
, 8, BZlib
371 static LONG
BZlib_CompressEnd(REG(a0
, bz_stream
*strm
)) {
373 return BZ2_bzCompressEnd(strm
);
380 static AROS_LH3(LONG
, DecompressInit
,
381 AROS_LHA(bz_stream
*, strm
, A0
),
382 AROS_LHA(LONG
, verbosity
, D0
),
383 AROS_LHA(LONG
, small
, D1
),
384 struct BZ2Base
*, libBase
, 9, BZlib
389 static LONG
BZlib_DecompressInit(REG(a0
, bz_stream
*strm
), REG(d0
, LONG verbosity
),
393 return BZ2_bzDecompressInit(strm
, verbosity
, small
);
400 static AROS_LH1(LONG
, Decompress
,
401 AROS_LHA(bz_stream
*, strm
, A0
),
402 struct BZ2Base
*, libBase
, 10, BZlib
407 static LONG
BZlib_Decompress(REG(a0
, bz_stream
*strm
)) {
409 return BZ2_bzDecompress(strm
);
416 static AROS_LH1(LONG
, DecompressEnd
,
417 AROS_LHA(bz_stream
*, strm
, A0
),
418 struct BZ2Base
*, libBase
, 11, BZlib
423 static LONG
BZlib_DecompressEnd(REG(a0
, bz_stream
*strm
)) {
425 return BZ2_bzDecompressEnd(strm
);
432 static AROS_LH7(LONG
, BuffToBuffCompress
,
433 AROS_LHA(APTR
, dest
, A0
),
434 AROS_LHA(ULONG
*, destLen
, A1
),
435 AROS_LHA(APTR
, source
, A2
),
436 AROS_LHA(ULONG
, sourceLen
, D0
),
437 AROS_LHA(LONG
, blockSize100k
, D1
),
438 AROS_LHA(LONG
, verbosity
, D2
),
439 AROS_LHA(LONG
, workFactor
, D3
),
440 struct BZ2Base
*, libBase
, 12, BZlib
445 static LONG
BZlib_BuffToBuffCompress(REG(a0
, APTR dest
), REG(a1
, ULONG
*destLen
),
446 REG(a2
, APTR source
), REG(d0
, ULONG sourceLen
), REG(d1
, LONG blockSize100k
),
447 REG(d2
, LONG verbosity
), REG(d3
, LONG workFactor
))
450 return BZ2_bzBuffToBuffCompress(dest
, (unsigned int *)destLen
, source
, sourceLen
,
451 blockSize100k
, verbosity
, workFactor
);
458 static AROS_LH6(LONG
, BuffToBuffDecompress
,
459 AROS_LHA(APTR
, dest
, A0
),
460 AROS_LHA(ULONG
*, destLen
, A1
),
461 AROS_LHA(APTR
, source
, A2
),
462 AROS_LHA(ULONG
, sourceLen
, D0
),
463 AROS_LHA(LONG
, small
, D1
),
464 AROS_LHA(LONG
, verbosity
, D2
),
465 struct BZ2Base
*, libBase
, 13, BZlib
470 static LONG
BZlib_BuffToBuffDecompress(REG(a0
, APTR dest
), REG(a1
, ULONG
*destLen
),
471 REG(a2
, APTR source
), REG(d0
, ULONG sourceLen
), REG(d1
, LONG small
),
472 REG(d2
, LONG verbosity
))
475 return BZ2_bzBuffToBuffDecompress(dest
, (unsigned int *)destLen
, source
, sourceLen
,
482 void bz_internal_error (int errcode
) {