ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
bzlib.c File Reference
#include "bzlib_private.h"
Include dependency graph for bzlib.c:

Go to the source code of this file.

Classes

struct  bzFile
 

Macros

#define ADD_CHAR_TO_BLOCK(zs, zchh0)
 
#define BZ_SETERR(eee)
 
#define SET_BINARY_MODE(file)
 

Functions

ABC_NAMESPACE_IMPL_START void BZ2_bz__AssertH__fail (int errcode)
 
int BZ_API BZ2_bzCompressInit (bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
 
int BZ_API BZ2_bzCompress (bz_stream *strm, int action)
 
int BZ_API BZ2_bzCompressEnd (bz_stream *strm)
 
int BZ_API BZ2_bzDecompressInit (bz_stream *strm, int verbosity, int small)
 
Int32 BZ2_indexIntoF (Int32 indx, Int32 *cftab)
 
int BZ_API BZ2_bzDecompress (bz_stream *strm)
 
int BZ_API BZ2_bzDecompressEnd (bz_stream *strm)
 
BZFILE *BZ_API BZ2_bzWriteOpen (int *bzerror, FILE *f, int blockSize100k, int verbosity, int workFactor)
 
void BZ_API BZ2_bzWrite (int *bzerror, BZFILE *b, void *buf, int len)
 
void BZ_API BZ2_bzWriteClose (int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
 
void BZ_API BZ2_bzWriteClose64 (int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in_lo32, unsigned int *nbytes_in_hi32, unsigned int *nbytes_out_lo32, unsigned int *nbytes_out_hi32)
 
BZFILE *BZ_API BZ2_bzReadOpen (int *bzerror, FILE *f, int verbosity, int small, void *unused, int nUnused)
 
void BZ_API BZ2_bzReadClose (int *bzerror, BZFILE *b)
 
int BZ_API BZ2_bzRead (int *bzerror, BZFILE *b, void *buf, int len)
 
void BZ_API BZ2_bzReadGetUnused (int *bzerror, BZFILE *b, void **unused, int *nUnused)
 
int BZ_API BZ2_bzBuffToBuffCompress (char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int blockSize100k, int verbosity, int workFactor)
 
int BZ_API BZ2_bzBuffToBuffDecompress (char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int small, int verbosity)
 
const char *BZ_API BZ2_bzlibVersion (void)
 
BZFILE *BZ_API BZ2_bzopen (const char *path, const char *mode)
 
BZFILE *BZ_API BZ2_bzdopen (int fd, const char *mode)
 
int BZ_API BZ2_bzread (BZFILE *b, void *buf, int len)
 
int BZ_API BZ2_bzwrite (BZFILE *b, void *buf, int len)
 
int BZ_API BZ2_bzflush (BZFILE *b)
 
void BZ_API BZ2_bzclose (BZFILE *b)
 
const char *BZ_API BZ2_bzerror (BZFILE *b, int *errnum)
 

Macro Definition Documentation

◆ ADD_CHAR_TO_BLOCK

#define ADD_CHAR_TO_BLOCK ( zs,
zchh0 )
Value:
{ \
UInt32 zchh = (UInt32)(zchh0); \
/*-- fast track the common case --*/ \
if (zchh != zs->state_in_ch && \
zs->state_in_len == 1) { \
UChar ch = (UChar)(zs->state_in_ch); \
BZ_UPDATE_CRC( zs->blockCRC, ch ); \
zs->inUse[zs->state_in_ch] = True; \
zs->block[zs->nblock] = (UChar)ch; \
zs->nblock++; \
zs->state_in_ch = zchh; \
} \
else \
/*-- general, uncommon cases --*/ \
if (zchh != zs->state_in_ch || \
zs->state_in_len == 255) { \
if (zs->state_in_ch < 256) \
add_pair_to_block ( zs ); \
zs->state_in_ch = zchh; \
zs->state_in_len = 1; \
} else { \
zs->state_in_len++; \
} \
}
unsigned int UInt32
unsigned char UChar
#define True

Definition at line 271 of file bzlib.c.

271#define ADD_CHAR_TO_BLOCK(zs,zchh0) \
272{ \
273 UInt32 zchh = (UInt32)(zchh0); \
274 /*-- fast track the common case --*/ \
275 if (zchh != zs->state_in_ch && \
276 zs->state_in_len == 1) { \
277 UChar ch = (UChar)(zs->state_in_ch); \
278 BZ_UPDATE_CRC( zs->blockCRC, ch ); \
279 zs->inUse[zs->state_in_ch] = True; \
280 zs->block[zs->nblock] = (UChar)ch; \
281 zs->nblock++; \
282 zs->state_in_ch = zchh; \
283 } \
284 else \
285 /*-- general, uncommon cases --*/ \
286 if (zchh != zs->state_in_ch || \
287 zs->state_in_len == 255) { \
288 if (zs->state_in_ch < 256) \
289 add_pair_to_block ( zs ); \
290 zs->state_in_ch = zchh; \
291 zs->state_in_len = 1; \
292 } else { \
293 zs->state_in_len++; \
294 } \
295}

◆ BZ_SETERR

#define BZ_SETERR ( eee)
Value:
{ \
if (bzerror != NULL) *bzerror = eee; \
if (bzf != NULL) bzf->lastErr = eee; \
}

Definition at line 897 of file bzlib.c.

897#define BZ_SETERR(eee) \
898{ \
899 if (bzerror != NULL) *bzerror = eee; \
900 if (bzf != NULL) bzf->lastErr = eee; \
901}

◆ SET_BINARY_MODE

#define SET_BINARY_MODE ( file)

Definition at line 1391 of file bzlib.c.

Function Documentation

◆ BZ2_bz__AssertH__fail()

ABC_NAMESPACE_IMPL_START void BZ2_bz__AssertH__fail ( int errcode)

Definition at line 52 of file bzlib.c.

53{
54 fprintf(stderr,
55 "\n\nbzip2/libbzip2: internal error number %d.\n"
56 "This is a bug in bzip2/libbzip2, %s.\n"
57 "Please report it to me at: jseward@bzip.org. If this happened\n"
58 "when you were using some program which uses libbzip2 as a\n"
59 "component, you should also report this bug to the author(s)\n"
60 "of that program. Please make an effort to report this bug;\n"
61 "timely and accurate bug reports eventually lead to higher\n"
62 "quality software. Thanks. Julian Seward, 10 December 2007.\n\n",
63 errcode,
65 );
66
67 if (errcode == 1007) {
68 fprintf(stderr,
69 "\n*** A special note about internal error number 1007 ***\n"
70 "\n"
71 "Experience suggests that a common cause of i.e. 1007\n"
72 "is unreliable memory or other hardware. The 1007 assertion\n"
73 "just happens to cross-check the results of huge numbers of\n"
74 "memory reads/writes, and so acts (unintendedly) as a stress\n"
75 "test of your memory system.\n"
76 "\n"
77 "I suggest the following: try compressing the file again,\n"
78 "possibly monitoring progress in detail with the -vv flag.\n"
79 "\n"
80 "* If the error cannot be reproduced, and/or happens at different\n"
81 " points in compression, you may have a flaky memory system.\n"
82 " Try a memory-test program. I have used Memtest86\n"
83 " (www.memtest86.com). At the time of writing it is free (GPLd).\n"
84 " Memtest86 tests memory much more thorougly than your BIOSs\n"
85 " power-on test, and may find failures that the BIOS doesn't.\n"
86 "\n"
87 "* If the error can be repeatably reproduced, this is a bug in\n"
88 " bzip2, and I would very much like to hear about it. Please\n"
89 " let me know, and, ideally, save a copy of the file causing the\n"
90 " problem -- without which I will be unable to investigate it.\n"
91 "\n"
92 );
93 }
94
95 exit(3);
96}
const char *BZ_API BZ2_bzlibVersion(void)
Definition bzlib.c:1377
VOID_HACK exit()
Here is the call graph for this function:

◆ BZ2_bzBuffToBuffCompress()

int BZ_API BZ2_bzBuffToBuffCompress ( char * dest,
unsigned int * destLen,
char * source,
unsigned int sourceLen,
int blockSize100k,
int verbosity,
int workFactor )

Definition at line 1258 of file bzlib.c.

1266{
1267 bz_stream strm;
1268 int ret;
1269
1270 if (dest == NULL || destLen == NULL ||
1271 source == NULL ||
1272 blockSize100k < 1 || blockSize100k > 9 ||
1273 verbosity < 0 || verbosity > 4 ||
1274 workFactor < 0 || workFactor > 250)
1275 return BZ_PARAM_ERROR;
1276
1277 if (workFactor == 0) workFactor = 30;
1278 strm.bzalloc = NULL;
1279 strm.bzfree = NULL;
1280 strm.opaque = NULL;
1281 ret = BZ2_bzCompressInit ( &strm, blockSize100k,
1282 verbosity, workFactor );
1283 if (ret != BZ_OK) return ret;
1284
1285 strm.next_in = source;
1286 strm.next_out = dest;
1287 strm.avail_in = sourceLen;
1288 strm.avail_out = *destLen;
1289
1290 ret = BZ2_bzCompress ( &strm, BZ_FINISH );
1291 if (ret == BZ_FINISH_OK) goto output_overflow;
1292 if (ret != BZ_STREAM_END) goto errhandler;
1293
1294 /* normal termination */
1295 *destLen -= strm.avail_out;
1296 BZ2_bzCompressEnd ( &strm );
1297 return BZ_OK;
1298
1299 output_overflow:
1300 BZ2_bzCompressEnd ( &strm );
1301 return BZ_OUTBUFF_FULL;
1302
1303 errhandler:
1304 BZ2_bzCompressEnd ( &strm );
1305 return ret;
1306}
int BZ_API BZ2_bzCompressInit(bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
Definition bzlib.c:160
int BZ_API BZ2_bzCompressEnd(bz_stream *strm)
Definition bzlib.c:479
int BZ_API BZ2_bzCompress(bz_stream *strm, int action)
Definition bzlib.c:418
#define BZ_OUTBUFF_FULL
Definition bzlib.h:46
#define BZ_FINISH_OK
Definition bzlib.h:37
#define BZ_PARAM_ERROR
Definition bzlib.h:40
#define BZ_OK
Definition bzlib.h:34
#define BZ_FINISH
Definition bzlib.h:32
#define BZ_STREAM_END
Definition bzlib.h:38
void(* bzfree)(void *, void *)
Definition bzlib.h:64
unsigned int avail_in
Definition bzlib.h:52
unsigned int avail_out
Definition bzlib.h:57
void *(* bzalloc)(void *, int, int)
Definition bzlib.h:63
void * opaque
Definition bzlib.h:65
char * next_in
Definition bzlib.h:51
char * next_out
Definition bzlib.h:56
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzBuffToBuffDecompress()

int BZ_API BZ2_bzBuffToBuffDecompress ( char * dest,
unsigned int * destLen,
char * source,
unsigned int sourceLen,
int small,
int verbosity )

Definition at line 1310 of file bzlib.c.

1317{
1318 bz_stream strm;
1319 int ret;
1320
1321 if (dest == NULL || destLen == NULL ||
1322 source == NULL ||
1323 (small != 0 && small != 1) ||
1324 verbosity < 0 || verbosity > 4)
1325 return BZ_PARAM_ERROR;
1326
1327 strm.bzalloc = NULL;
1328 strm.bzfree = NULL;
1329 strm.opaque = NULL;
1330 ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
1331 if (ret != BZ_OK) return ret;
1332
1333 strm.next_in = source;
1334 strm.next_out = dest;
1335 strm.avail_in = sourceLen;
1336 strm.avail_out = *destLen;
1337
1338 ret = BZ2_bzDecompress ( &strm );
1339 if (ret == BZ_OK) goto output_overflow_or_eof;
1340 if (ret != BZ_STREAM_END) goto errhandler;
1341
1342 /* normal termination */
1343 *destLen -= strm.avail_out;
1344 BZ2_bzDecompressEnd ( &strm );
1345 return BZ_OK;
1346
1347 output_overflow_or_eof:
1348 if (strm.avail_out > 0) {
1349 BZ2_bzDecompressEnd ( &strm );
1350 return BZ_UNEXPECTED_EOF;
1351 } else {
1352 BZ2_bzDecompressEnd ( &strm );
1353 return BZ_OUTBUFF_FULL;
1354 };
1355
1356 errhandler:
1357 BZ2_bzDecompressEnd ( &strm );
1358 return ret;
1359}
int BZ_API BZ2_bzDecompressInit(bz_stream *strm, int verbosity, int small)
Definition bzlib.c:504
int BZ_API BZ2_bzDecompress(bz_stream *strm)
Definition bzlib.c:819
int BZ_API BZ2_bzDecompressEnd(bz_stream *strm)
Definition bzlib.c:873
#define BZ_UNEXPECTED_EOF
Definition bzlib.h:45
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzclose()

void BZ_API BZ2_bzclose ( BZFILE * b)

Definition at line 1525 of file bzlib.c.

1526{
1527 int bzerr;
1528 FILE *fp;
1529
1530 if (b==NULL) {return;}
1531 fp = ((bzFile *)b)->handle;
1532 if(((bzFile*)b)->writing){
1533 BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
1534 if(bzerr != BZ_OK){
1535 BZ2_bzWriteClose(NULL,b,1,NULL,NULL);
1536 }
1537 }else{
1538 BZ2_bzReadClose(&bzerr,b);
1539 }
1540 if(fp!=stdin && fp!=stdout){
1541 fclose(fp);
1542 }
1543}
void BZ_API BZ2_bzReadClose(int *bzerror, BZFILE *b)
Definition bzlib.c:1154
void BZ_API BZ2_bzWriteClose(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
Definition bzlib.c:1021
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzCompress()

int BZ_API BZ2_bzCompress ( bz_stream * strm,
int action )

Definition at line 418 of file bzlib.c.

419{
420 Bool progress;
421 EState* s;
422 if (strm == NULL) return BZ_PARAM_ERROR;
423 s = (EState *)strm->state;
424 if (s == NULL) return BZ_PARAM_ERROR;
425 if (s->strm != strm) return BZ_PARAM_ERROR;
426
427 preswitch:
428 switch (s->mode) {
429
430 case BZ_M_IDLE:
431 return BZ_SEQUENCE_ERROR;
432
433 case BZ_M_RUNNING:
434 if (action == BZ_RUN) {
435 progress = handle_compress ( strm );
436 return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
437 }
438 else
439 if (action == BZ_FLUSH) {
440 s->avail_in_expect = strm->avail_in;
441 s->mode = BZ_M_FLUSHING;
442 goto preswitch;
443 }
444 else
445 if (action == BZ_FINISH) {
446 s->avail_in_expect = strm->avail_in;
447 s->mode = BZ_M_FINISHING;
448 goto preswitch;
449 }
450 else
451 return BZ_PARAM_ERROR;
452
453 case BZ_M_FLUSHING:
454 if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
455 if (s->avail_in_expect != s->strm->avail_in)
456 return BZ_SEQUENCE_ERROR;
457 progress = handle_compress ( strm );
458 if (s->avail_in_expect > 0 || !isempty_RL(s) ||
459 s->state_out_pos < s->numZ) return BZ_FLUSH_OK;
460 s->mode = BZ_M_RUNNING;
461 return BZ_RUN_OK;
462
463 case BZ_M_FINISHING:
464 if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
465 if (s->avail_in_expect != s->strm->avail_in)
466 return BZ_SEQUENCE_ERROR;
467 progress = handle_compress ( strm );
468 if (!progress) return BZ_SEQUENCE_ERROR;
469 if (s->avail_in_expect > 0 || !isempty_RL(s) ||
470 s->state_out_pos < s->numZ) return BZ_FINISH_OK;
471 s->mode = BZ_M_IDLE;
472 return BZ_STREAM_END;
473 }
474 return BZ_OK; /*--not reached--*/
475}
#define BZ_RUN_OK
Definition bzlib.h:35
#define BZ_SEQUENCE_ERROR
Definition bzlib.h:39
#define BZ_FLUSH_OK
Definition bzlib.h:36
#define BZ_RUN
Definition bzlib.h:30
#define BZ_FLUSH
Definition bzlib.h:31
#define BZ_M_RUNNING
unsigned char Bool
#define BZ_M_FINISHING
#define BZ_M_IDLE
#define BZ_M_FLUSHING
UInt32 avail_in_expect
bz_stream * strm
Int32 numZ
Int32 state_out_pos
Int32 mode
void * state
Definition bzlib.h:61
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzCompressEnd()

int BZ_API BZ2_bzCompressEnd ( bz_stream * strm)

Definition at line 479 of file bzlib.c.

480{
481 EState* s;
482 if (strm == NULL) return BZ_PARAM_ERROR;
483 s = (EState *)strm->state;
484 if (s == NULL) return BZ_PARAM_ERROR;
485 if (s->strm != strm) return BZ_PARAM_ERROR;
486
487 if (s->arr1 != NULL) BZFREE(s->arr1);
488 if (s->arr2 != NULL) BZFREE(s->arr2);
489 if (s->ftab != NULL) BZFREE(s->ftab);
490 BZFREE(strm->state);
491
492 strm->state = NULL;
493
494 return BZ_OK;
495}
#define BZFREE(ppp)
UInt32 * ftab
UInt32 * arr1
UInt32 * arr2
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzCompressInit()

int BZ_API BZ2_bzCompressInit ( bz_stream * strm,
int blockSize100k,
int verbosity,
int workFactor )

Definition at line 159 of file bzlib.c.

164{
165 Int32 n;
166 EState* s;
167
168 if (!bz_config_ok()) return BZ_CONFIG_ERROR;
169
170 if (strm == NULL ||
171 blockSize100k < 1 || blockSize100k > 9 ||
172 workFactor < 0 || workFactor > 250)
173 return BZ_PARAM_ERROR;
174
175 if (workFactor == 0) workFactor = 30;
176 if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
177 if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
178
179 s = (EState *)BZALLOC( sizeof(EState) );
180 if (s == NULL) return BZ_MEM_ERROR;
181 s->strm = strm;
182
183 s->arr1 = NULL;
184 s->arr2 = NULL;
185 s->ftab = NULL;
186
187 n = 100000 * blockSize100k;
188 s->arr1 = (unsigned *)BZALLOC( n * sizeof(UInt32) );
189 s->arr2 = (unsigned *)BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
190 s->ftab = (unsigned *)BZALLOC( 65537 * sizeof(UInt32) );
191
192 if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
193 if (s->arr1 != NULL) BZFREE(s->arr1);
194 if (s->arr2 != NULL) BZFREE(s->arr2);
195 if (s->ftab != NULL) BZFREE(s->ftab);
196 if (s != NULL) BZFREE(s);
197 return BZ_MEM_ERROR;
198 }
199
200 s->blockNo = 0;
201 s->state = BZ_S_INPUT;
202 s->mode = BZ_M_RUNNING;
203 s->combinedCRC = 0;
204 s->blockSize100k = blockSize100k;
205 s->nblockMAX = 100000 * blockSize100k - 19;
206 s->verbosity = verbosity;
207 s->workFactor = workFactor;
208
209 s->block = (UChar*)s->arr2;
210 s->mtfv = (UInt16*)s->arr1;
211 s->zbits = NULL;
212 s->ptr = (UInt32*)s->arr1;
213
214 strm->state = s;
215 strm->total_in_lo32 = 0;
216 strm->total_in_hi32 = 0;
217 strm->total_out_lo32 = 0;
218 strm->total_out_hi32 = 0;
219 init_RL ( s );
220 prepare_new_block ( s );
221 return BZ_OK;
222}
#define BZ_MEM_ERROR
Definition bzlib.h:41
#define BZ_CONFIG_ERROR
Definition bzlib.h:47
#define BZALLOC(nnn)
#define BZ_N_OVERSHOOT
#define BZ_S_INPUT
unsigned short UInt16
int Int32
UChar * block
UInt16 * mtfv
UInt32 combinedCRC
Int32 state
Int32 nblockMAX
Int32 workFactor
UInt32 * ptr
Int32 blockSize100k
Int32 verbosity
Int32 blockNo
UChar * zbits
unsigned int total_out_lo32
Definition bzlib.h:58
unsigned int total_out_hi32
Definition bzlib.h:59
unsigned int total_in_lo32
Definition bzlib.h:53
unsigned int total_in_hi32
Definition bzlib.h:54
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzDecompress()

int BZ_API BZ2_bzDecompress ( bz_stream * strm)

Definition at line 819 of file bzlib.c.

820{
821 Bool corrupt;
822 DState* s;
823 if (strm == NULL) return BZ_PARAM_ERROR;
824 s = (DState *)strm->state;
825 if (s == NULL) return BZ_PARAM_ERROR;
826 if (s->strm != strm) return BZ_PARAM_ERROR;
827
828 while (True) {
829 if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
830 if (s->state == BZ_X_OUTPUT) {
831 if (s->smallDecompress)
832 corrupt = unRLE_obuf_to_output_SMALL ( s ); else
833 corrupt = unRLE_obuf_to_output_FAST ( s );
834 if (corrupt) return BZ_DATA_ERROR;
835 if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
837 if (s->verbosity >= 3)
838 VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC,
840 if (s->verbosity >= 2) VPrintf0 ( "]" );
842 return BZ_DATA_ERROR;
844 = (s->calculatedCombinedCRC << 1) |
845 (s->calculatedCombinedCRC >> 31);
847 s->state = BZ_X_BLKHDR_1;
848 } else {
849 return BZ_OK;
850 }
851 }
852 if (s->state >= BZ_X_MAGIC_1) {
853 Int32 r = BZ2_decompress ( s );
854 if (r == BZ_STREAM_END) {
855 if (s->verbosity >= 3)
856 VPrintf2 ( "\n combined CRCs: stored = 0x%08x, computed = 0x%08x",
859 return BZ_DATA_ERROR;
860 return r;
861 }
862 if (s->state != BZ_X_OUTPUT) return r;
863 }
864 }
865
866 AssertH ( 0, 6001 );
867
868 return 0; /*NOTREACHED*/
869}
#define BZ_DATA_ERROR
Definition bzlib.h:42
#define BZ_X_IDLE
#define BZ_X_MAGIC_1
#define BZ_X_BLKHDR_1
#define VPrintf2(zf, za1, za2)
#define AssertH(cond, errcode)
Int32 BZ2_decompress(DState *)
Definition decompress.c:113
#define BZ_X_OUTPUT
#define VPrintf0(zf)
#define BZ_FINALISE_CRC(crcVar)
UInt32 calculatedBlockCRC
bz_stream * strm
Bool smallDecompress
UInt32 calculatedCombinedCRC
UInt32 storedBlockCRC
UInt32 storedCombinedCRC
Int32 save_nblock
Int32 state_out_len
Int32 nblock_used
Int32 state
Int32 verbosity
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzDecompressEnd()

int BZ_API BZ2_bzDecompressEnd ( bz_stream * strm)

Definition at line 873 of file bzlib.c.

874{
875 DState* s;
876 if (strm == NULL) return BZ_PARAM_ERROR;
877 s = (DState *)strm->state;
878 if (s == NULL) return BZ_PARAM_ERROR;
879 if (s->strm != strm) return BZ_PARAM_ERROR;
880
881 if (s->tt != NULL) BZFREE(s->tt);
882 if (s->ll16 != NULL) BZFREE(s->ll16);
883 if (s->ll4 != NULL) BZFREE(s->ll4);
884
885 BZFREE(strm->state);
886 strm->state = NULL;
887
888 return BZ_OK;
889}
UInt32 * tt
UChar * ll4
UInt16 * ll16
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzDecompressInit()

int BZ_API BZ2_bzDecompressInit ( bz_stream * strm,
int verbosity,
int small )

Definition at line 503 of file bzlib.c.

507{
508 DState* s;
509
510 if (!bz_config_ok()) return BZ_CONFIG_ERROR;
511
512 if (strm == NULL) return BZ_PARAM_ERROR;
513 if (small != 0 && small != 1) return BZ_PARAM_ERROR;
514 if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR;
515
516 if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
517 if (strm->bzfree == NULL) strm->bzfree = default_bzfree;
518
519 s = (DState *)BZALLOC( sizeof(DState) );
520 if (s == NULL) return BZ_MEM_ERROR;
521 s->strm = strm;
522 strm->state = s;
523 s->state = BZ_X_MAGIC_1;
524 s->bsLive = 0;
525 s->bsBuff = 0;
527 strm->total_in_lo32 = 0;
528 strm->total_in_hi32 = 0;
529 strm->total_out_lo32 = 0;
530 strm->total_out_hi32 = 0;
531 s->smallDecompress = (Bool)small;
532 s->ll4 = NULL;
533 s->ll16 = NULL;
534 s->tt = NULL;
535 s->currBlockNo = 0;
536 s->verbosity = verbosity;
537
538 return BZ_OK;
539}
Int32 currBlockNo
Int32 bsLive
UInt32 bsBuff
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzdopen()

BZFILE *BZ_API BZ2_bzdopen ( int fd,
const char * mode )

Definition at line 1480 of file bzlib.c.

1483{
1484 return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1);
1485}
Definition mode.h:11
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzerror()

const char *BZ_API BZ2_bzerror ( BZFILE * b,
int * errnum )

Definition at line 1570 of file bzlib.c.

1571{
1572 int err = ((bzFile *)b)->lastErr;
1573
1574 if(err>0) err = 0;
1575 *errnum = err;
1576 return bzerrorstrings[err*-1];
1577}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzflush()

int BZ_API BZ2_bzflush ( BZFILE * b)

Definition at line 1517 of file bzlib.c.

1518{
1519 /* do nothing now... */
1520 return 0;
1521}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzlibVersion()

const char *BZ_API BZ2_bzlibVersion ( void )

Definition at line 1377 of file bzlib.c.

1378{
1379 return BZ_VERSION;
1380}
#define BZ_VERSION
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzopen()

BZFILE *BZ_API BZ2_bzopen ( const char * path,
const char * mode )

Definition at line 1471 of file bzlib.c.

1474{
1475 return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0);
1476}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzRead()

int BZ_API BZ2_bzRead ( int * bzerror,
BZFILE * b,
void * buf,
int len )

Definition at line 1172 of file bzlib.c.

1177{
1178 Int32 n, ret;
1179 bzFile* bzf = (bzFile*)b;
1180
1182
1183 if (bzf == NULL || buf == NULL || len < 0)
1184 { BZ_SETERR(BZ_PARAM_ERROR); return 0; };
1185
1186 if (bzf->writing)
1187 { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };
1188
1189 if (len == 0)
1190 { BZ_SETERR(BZ_OK); return 0; };
1191
1192 bzf->strm.avail_out = len;
1193 bzf->strm.next_out = (char *)buf;
1194
1195 while (True) {
1196
1197 if (ferror(bzf->handle))
1198 { BZ_SETERR(BZ_IO_ERROR); return 0; };
1199
1200 if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
1201 n = fread ( bzf->buf, sizeof(UChar),
1202 BZ_MAX_UNUSED, bzf->handle );
1203 if (ferror(bzf->handle))
1204 { BZ_SETERR(BZ_IO_ERROR); return 0; };
1205 bzf->bufN = n;
1206 bzf->strm.avail_in = bzf->bufN;
1207 bzf->strm.next_in = bzf->buf;
1208 }
1209
1210 ret = BZ2_bzDecompress ( &(bzf->strm) );
1211
1212 if (ret != BZ_OK && ret != BZ_STREAM_END)
1213 { BZ_SETERR(ret); return 0; };
1214
1215 if (ret == BZ_OK && myfeof(bzf->handle) &&
1216 bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
1217 { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };
1218
1219 if (ret == BZ_STREAM_END)
1221 return len - bzf->strm.avail_out; };
1222 if (bzf->strm.avail_out == 0)
1223 { BZ_SETERR(BZ_OK); return len; };
1224
1225 }
1226
1227 return 0; /*not reached*/
1228}
#define BZ_SETERR(eee)
Definition bzlib.c:897
#define BZ_IO_ERROR
Definition bzlib.h:44
#define BZ_MAX_UNUSED
Definition bzlib.h:140
FILE * handle
Definition bzlib.c:905
Int32 bufN
Definition bzlib.c:907
Char buf[BZ_MAX_UNUSED]
Definition bzlib.c:906
bz_stream strm
Definition bzlib.c:909
Bool writing
Definition bzlib.c:908
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzread()

int BZ_API BZ2_bzread ( BZFILE * b,
void * buf,
int len )

Definition at line 1489 of file bzlib.c.

1490{
1491 int bzerr, nread;
1492 if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0;
1493 nread = BZ2_bzRead(&bzerr,b,buf,len);
1494 if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) {
1495 return nread;
1496 } else {
1497 return -1;
1498 }
1499}
int BZ_API BZ2_bzRead(int *bzerror, BZFILE *b, void *buf, int len)
Definition bzlib.c:1173
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzReadClose()

void BZ_API BZ2_bzReadClose ( int * bzerror,
BZFILE * b )

Definition at line 1154 of file bzlib.c.

1155{
1156 bzFile* bzf = (bzFile*)b;
1157
1159 if (bzf == NULL)
1160 { BZ_SETERR(BZ_OK); return; };
1161
1162 if (bzf->writing)
1163 { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
1164
1165 if (bzf->initialisedOk)
1166 (void)BZ2_bzDecompressEnd ( &(bzf->strm) );
1167 free ( bzf );
1168}
Bool initialisedOk
Definition bzlib.c:911
VOID_HACK free()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzReadGetUnused()

void BZ_API BZ2_bzReadGetUnused ( int * bzerror,
BZFILE * b,
void ** unused,
int * nUnused )

Definition at line 1232 of file bzlib.c.

1237{
1238 bzFile* bzf = (bzFile*)b;
1239 if (bzf == NULL)
1240 { BZ_SETERR(BZ_PARAM_ERROR); return; };
1241 if (bzf->lastErr != BZ_STREAM_END)
1242 { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
1243 if (unused == NULL || nUnused == NULL)
1244 { BZ_SETERR(BZ_PARAM_ERROR); return; };
1245
1247 *nUnused = bzf->strm.avail_in;
1248 *unused = bzf->strm.next_in;
1249}
Int32 lastErr
Definition bzlib.c:910
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzReadOpen()

BZFILE *BZ_API BZ2_bzReadOpen ( int * bzerror,
FILE * f,
int verbosity,
int small,
void * unused,
int nUnused )

Definition at line 1098 of file bzlib.c.

1105{
1106 bzFile* bzf = NULL;
1107 int ret;
1108
1110
1111 if (f == NULL ||
1112 (small != 0 && small != 1) ||
1113 (verbosity < 0 || verbosity > 4) ||
1114 (unused == NULL && nUnused != 0) ||
1115 (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)))
1116 { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
1117
1118 if (ferror(f))
1119 { BZ_SETERR(BZ_IO_ERROR); return NULL; };
1120
1121 bzf = (bzFile *)malloc ( sizeof(bzFile) );
1122 if (bzf == NULL)
1123 { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
1124
1126
1127 bzf->initialisedOk = False;
1128 bzf->handle = f;
1129 bzf->bufN = 0;
1130 bzf->writing = False;
1131 bzf->strm.bzalloc = NULL;
1132 bzf->strm.bzfree = NULL;
1133 bzf->strm.opaque = NULL;
1134
1135 while (nUnused > 0) {
1136 bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
1137 unused = ((void*)( 1 + ((UChar*)(unused)) ));
1138 nUnused--;
1139 }
1140
1141 ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small );
1142 if (ret != BZ_OK)
1143 { BZ_SETERR(ret); free(bzf); return NULL; };
1144
1145 bzf->strm.avail_in = bzf->bufN;
1146 bzf->strm.next_in = bzf->buf;
1147
1148 bzf->initialisedOk = True;
1149 return bzf;
1150}
#define False
char * malloc()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzWrite()

void BZ_API BZ2_bzWrite ( int * bzerror,
BZFILE * b,
void * buf,
int len )

Definition at line 975 of file bzlib.c.

980{
981 Int32 n, n2, ret;
982 bzFile* bzf = (bzFile*)b;
983
985 if (bzf == NULL || buf == NULL || len < 0)
986 { BZ_SETERR(BZ_PARAM_ERROR); return; };
987 if (!(bzf->writing))
988 { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
989 if (ferror(bzf->handle))
990 { BZ_SETERR(BZ_IO_ERROR); return; };
991
992 if (len == 0)
993 { BZ_SETERR(BZ_OK); return; };
994
995 bzf->strm.avail_in = len;
996 bzf->strm.next_in = (char *)buf;
997
998 while (True) {
1000 bzf->strm.next_out = bzf->buf;
1001 ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN );
1002 if (ret != BZ_RUN_OK)
1003 { BZ_SETERR(ret); return; };
1004
1005 if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
1006 n = BZ_MAX_UNUSED - bzf->strm.avail_out;
1007 n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
1008 n, bzf->handle );
1009 if (n != n2 || ferror(bzf->handle))
1010 { BZ_SETERR(BZ_IO_ERROR); return; };
1011 }
1012
1013 if (bzf->strm.avail_in == 0)
1014 { BZ_SETERR(BZ_OK); return; };
1015 }
1016}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzwrite()

int BZ_API BZ2_bzwrite ( BZFILE * b,
void * buf,
int len )

Definition at line 1503 of file bzlib.c.

1504{
1505 int bzerr;
1506
1507 BZ2_bzWrite(&bzerr,b,buf,len);
1508 if(bzerr == BZ_OK){
1509 return len;
1510 }else{
1511 return -1;
1512 }
1513}
void BZ_API BZ2_bzWrite(int *bzerror, BZFILE *b, void *buf, int len)
Definition bzlib.c:976
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzWriteClose()

void BZ_API BZ2_bzWriteClose ( int * bzerror,
BZFILE * b,
int abandon,
unsigned int * nbytes_in,
unsigned int * nbytes_out )

Definition at line 1020 of file bzlib.c.

1026{
1027 BZ2_bzWriteClose64 ( bzerror, b, abandon,
1028 nbytes_in, NULL, nbytes_out, NULL );
1029}
void BZ_API BZ2_bzWriteClose64(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in_lo32, unsigned int *nbytes_in_hi32, unsigned int *nbytes_out_lo32, unsigned int *nbytes_out_hi32)
Definition bzlib.c:1033
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzWriteClose64()

void BZ_API BZ2_bzWriteClose64 ( int * bzerror,
BZFILE * b,
int abandon,
unsigned int * nbytes_in_lo32,
unsigned int * nbytes_in_hi32,
unsigned int * nbytes_out_lo32,
unsigned int * nbytes_out_hi32 )

Definition at line 1032 of file bzlib.c.

1040{
1041 Int32 n, n2, ret;
1042 bzFile* bzf = (bzFile*)b;
1043
1044 if (bzf == NULL)
1045 { BZ_SETERR(BZ_OK); return; };
1046 if (!(bzf->writing))
1047 { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
1048 if (ferror(bzf->handle))
1049 { BZ_SETERR(BZ_IO_ERROR); return; };
1050
1051 if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0;
1052 if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0;
1053 if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0;
1054 if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0;
1055
1056 if ((!abandon) && bzf->lastErr == BZ_OK) {
1057 while (True) {
1059 bzf->strm.next_out = bzf->buf;
1060 ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH );
1061 if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
1062 { BZ_SETERR(ret); return; };
1063
1064 if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
1065 n = BZ_MAX_UNUSED - bzf->strm.avail_out;
1066 n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar),
1067 n, bzf->handle );
1068 if (n != n2 || ferror(bzf->handle))
1069 { BZ_SETERR(BZ_IO_ERROR); return; };
1070 }
1071
1072 if (ret == BZ_STREAM_END) break;
1073 }
1074 }
1075
1076 if ( !abandon && !ferror ( bzf->handle ) ) {
1077 fflush ( bzf->handle );
1078 if (ferror(bzf->handle))
1079 { BZ_SETERR(BZ_IO_ERROR); return; };
1080 }
1081
1082 if (nbytes_in_lo32 != NULL)
1083 *nbytes_in_lo32 = bzf->strm.total_in_lo32;
1084 if (nbytes_in_hi32 != NULL)
1085 *nbytes_in_hi32 = bzf->strm.total_in_hi32;
1086 if (nbytes_out_lo32 != NULL)
1087 *nbytes_out_lo32 = bzf->strm.total_out_lo32;
1088 if (nbytes_out_hi32 != NULL)
1089 *nbytes_out_hi32 = bzf->strm.total_out_hi32;
1090
1092 BZ2_bzCompressEnd ( &(bzf->strm) );
1093 free ( bzf );
1094}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_bzWriteOpen()

BZFILE *BZ_API BZ2_bzWriteOpen ( int * bzerror,
FILE * f,
int blockSize100k,
int verbosity,
int workFactor )

Definition at line 927 of file bzlib.c.

933{
934 Int32 ret;
935 bzFile* bzf = NULL;
936
938
939 if (f == NULL ||
940 (blockSize100k < 1 || blockSize100k > 9) ||
941 (workFactor < 0 || workFactor > 250) ||
942 (verbosity < 0 || verbosity > 4))
943 { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };
944
945 if (ferror(f))
946 { BZ_SETERR(BZ_IO_ERROR); return NULL; };
947
948 bzf = (bzFile *)malloc ( sizeof(bzFile) );
949 if (bzf == NULL)
950 { BZ_SETERR(BZ_MEM_ERROR); return NULL; };
951
953 bzf->initialisedOk = False;
954 bzf->bufN = 0;
955 bzf->handle = f;
956 bzf->writing = True;
957 bzf->strm.bzalloc = NULL;
958 bzf->strm.bzfree = NULL;
959 bzf->strm.opaque = NULL;
960
961 if (workFactor == 0) workFactor = 30;
962 ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k,
963 verbosity, workFactor );
964 if (ret != BZ_OK)
965 { BZ_SETERR(ret); free(bzf); return NULL; };
966
967 bzf->strm.avail_in = 0;
968 bzf->initialisedOk = True;
969 return bzf;
970}
Here is the call graph for this function:
Here is the caller graph for this function:

◆ BZ2_indexIntoF()

Int32 BZ2_indexIntoF ( Int32 indx,
Int32 * cftab )

Definition at line 698 of file bzlib.c.

699{
700 Int32 nb, na, mid;
701 nb = 0;
702 na = 256;
703 do {
704 mid = (nb + na) >> 1;
705 if (indx >= cftab[mid]) nb = mid; else na = mid;
706 }
707 while (na - nb != 1);
708 return nb;
709}