abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bzlib.h File Reference
#include <stdio.h>
#include "misc/util/abc_global.h"

Go to the source code of this file.

Data Structures

struct  bz_stream
 

Macros

#define ABC__misc__bzlib__bzlib_h
 
#define BZ_RUN   0
 
#define BZ_FLUSH   1
 
#define BZ_FINISH   2
 
#define BZ_OK   0
 
#define BZ_RUN_OK   1
 
#define BZ_FLUSH_OK   2
 
#define BZ_FINISH_OK   3
 
#define BZ_STREAM_END   4
 
#define BZ_SEQUENCE_ERROR   (-1)
 
#define BZ_PARAM_ERROR   (-2)
 
#define BZ_MEM_ERROR   (-3)
 
#define BZ_DATA_ERROR   (-4)
 
#define BZ_DATA_ERROR_MAGIC   (-5)
 
#define BZ_IO_ERROR   (-6)
 
#define BZ_UNEXPECTED_EOF   (-7)
 
#define BZ_OUTBUFF_FULL   (-8)
 
#define BZ_CONFIG_ERROR   (-9)
 
#define BZ_EXPORT
 
#define BZ_API(func)   func
 
#define BZ_EXTERN   extern
 
#define BZ_MAX_UNUSED   5000
 

Typedefs

typedef void BZFILE
 

Functions

ABC_NAMESPACE_HEADER_START
BZ_EXTERN int BZ_API() 
BZ2_bzCompressInit (bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
 
BZ_EXTERN int BZ_API() BZ2_bzCompress (bz_stream *strm, int action)
 
BZ_EXTERN int BZ_API() BZ2_bzCompressEnd (bz_stream *strm)
 
BZ_EXTERN int BZ_API() BZ2_bzDecompressInit (bz_stream *strm, int verbosity, int small)
 
BZ_EXTERN int BZ_API() BZ2_bzDecompress (bz_stream *strm)
 
BZ_EXTERN int BZ_API() BZ2_bzDecompressEnd (bz_stream *strm)
 
BZ_EXTERN BZFILE *BZ_API() BZ2_bzReadOpen (int *bzerror, FILE *f, int verbosity, int small, void *unused, int nUnused)
 
BZ_EXTERN void BZ_API() BZ2_bzReadClose (int *bzerror, BZFILE *b)
 
BZ_EXTERN void BZ_API() BZ2_bzReadGetUnused (int *bzerror, BZFILE *b, void **unused, int *nUnused)
 
BZ_EXTERN int BZ_API() BZ2_bzRead (int *bzerror, BZFILE *b, void *buf, int len)
 
BZ_EXTERN BZFILE *BZ_API() BZ2_bzWriteOpen (int *bzerror, FILE *f, int blockSize100k, int verbosity, int workFactor)
 
BZ_EXTERN void BZ_API() BZ2_bzWrite (int *bzerror, BZFILE *b, void *buf, int len)
 
BZ_EXTERN void BZ_API() BZ2_bzWriteClose (int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
 
BZ_EXTERN 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)
 
BZ_EXTERN int BZ_API() BZ2_bzBuffToBuffCompress (char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int blockSize100k, int verbosity, int workFactor)
 
BZ_EXTERN int BZ_API() BZ2_bzBuffToBuffDecompress (char *dest, unsigned int *destLen, char *source, unsigned int sourceLen, int small, int verbosity)
 
BZ_EXTERN const char *BZ_API() BZ2_bzlibVersion (void)
 
BZ_EXTERN BZFILE *BZ_API() BZ2_bzopen (const char *path, const char *mode)
 
BZ_EXTERN BZFILE *BZ_API() BZ2_bzdopen (int fd, const char *mode)
 
BZ_EXTERN int BZ_API() BZ2_bzread (BZFILE *b, void *buf, int len)
 
BZ_EXTERN int BZ_API() BZ2_bzwrite (BZFILE *b, void *buf, int len)
 
BZ_EXTERN int BZ_API() BZ2_bzflush (BZFILE *b)
 
BZ_EXTERN void BZ_API() BZ2_bzclose (BZFILE *b)
 
BZ_EXTERN const char *BZ_API() BZ2_bzerror (BZFILE *b, int *errnum)
 

Macro Definition Documentation

#define ABC__misc__bzlib__bzlib_h

Definition at line 28 of file bzlib.h.

#define BZ_API (   func)    func

Definition at line 94 of file bzlib.h.

#define BZ_CONFIG_ERROR   (-9)

Definition at line 47 of file bzlib.h.

#define BZ_DATA_ERROR   (-4)

Definition at line 42 of file bzlib.h.

#define BZ_DATA_ERROR_MAGIC   (-5)

Definition at line 43 of file bzlib.h.

#define BZ_EXPORT

Definition at line 71 of file bzlib.h.

#define BZ_EXTERN   extern

Definition at line 95 of file bzlib.h.

#define BZ_FINISH   2

Definition at line 32 of file bzlib.h.

#define BZ_FINISH_OK   3

Definition at line 37 of file bzlib.h.

#define BZ_FLUSH   1

Definition at line 31 of file bzlib.h.

#define BZ_FLUSH_OK   2

Definition at line 36 of file bzlib.h.

#define BZ_IO_ERROR   (-6)

Definition at line 44 of file bzlib.h.

#define BZ_MAX_UNUSED   5000

Definition at line 140 of file bzlib.h.

#define BZ_MEM_ERROR   (-3)

Definition at line 41 of file bzlib.h.

#define BZ_OK   0

Definition at line 34 of file bzlib.h.

#define BZ_OUTBUFF_FULL   (-8)

Definition at line 46 of file bzlib.h.

#define BZ_PARAM_ERROR   (-2)

Definition at line 40 of file bzlib.h.

#define BZ_RUN   0

Definition at line 30 of file bzlib.h.

#define BZ_RUN_OK   1

Definition at line 35 of file bzlib.h.

#define BZ_SEQUENCE_ERROR   (-1)

Definition at line 39 of file bzlib.h.

#define BZ_STREAM_END   4

Definition at line 38 of file bzlib.h.

#define BZ_UNEXPECTED_EOF   (-7)

Definition at line 45 of file bzlib.h.

Typedef Documentation

typedef void BZFILE

Definition at line 142 of file bzlib.h.

Function Documentation

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

Definition at line 1259 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_bzCompress(bz_stream *strm, int action)
Definition: bzlib.c:418
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
#define BZ_FINISH
Definition: bzlib.h:32
int BZ_API() BZ2_bzCompressEnd(bz_stream *strm)
Definition: bzlib.c:479
int BZ_API() BZ2_bzCompressInit(bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
Definition: bzlib.c:160
#define BZ_OK
Definition: bzlib.h:34
#define BZ_STREAM_END
Definition: bzlib.h:38
#define BZ_FINISH_OK
Definition: bzlib.h:37
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
#define BZ_OUTBUFF_FULL
Definition: bzlib.h:46
unsigned int avail_out
Definition: bzlib.h:57
void * opaque
Definition: bzlib.h:65
char * next_out
Definition: bzlib.h:56
char * next_in
Definition: bzlib.h:51
BZ_EXTERN int BZ_API() BZ2_bzBuffToBuffDecompress ( char *  dest,
unsigned int *  destLen,
char *  source,
unsigned int  sourceLen,
int  small,
int  verbosity 
)

Definition at line 1311 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_bzDecompress(bz_stream *strm)
Definition: bzlib.c:819
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
#define BZ_OK
Definition: bzlib.h:34
#define BZ_STREAM_END
Definition: bzlib.h:38
int BZ_API() BZ2_bzDecompressInit(bz_stream *strm, int verbosity, int small)
Definition: bzlib.c:504
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
int BZ_API() BZ2_bzDecompressEnd(bz_stream *strm)
Definition: bzlib.c:873
#define BZ_UNEXPECTED_EOF
Definition: bzlib.h:45
#define BZ_OUTBUFF_FULL
Definition: bzlib.h:46
unsigned int avail_out
Definition: bzlib.h:57
void * opaque
Definition: bzlib.h:65
char * next_out
Definition: bzlib.h:56
char * next_in
Definition: bzlib.h:51
BZ_EXTERN 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_bzWriteClose(int *bzerror, BZFILE *b, int abandon, unsigned int *nbytes_in, unsigned int *nbytes_out)
Definition: bzlib.c:1021
void BZ_API() BZ2_bzReadClose(int *bzerror, BZFILE *b)
Definition: bzlib.c:1154
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
BZ_EXTERN 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_FLUSH
Definition: bzlib.h:31
Int32 state_out_pos
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
#define BZ_FINISH
Definition: bzlib.h:32
bz_stream * strm
static Bool isempty_RL(EState *s)
Definition: bzlib.c:150
unsigned char Bool
Definition: bzlib_private.h:44
static Bool handle_compress(bz_stream *strm)
Definition: bzlib.c:372
#define BZ_M_FINISHING
#define BZ_OK
Definition: bzlib.h:34
#define BZ_RUN
Definition: bzlib.h:30
#define BZ_STREAM_END
Definition: bzlib.h:38
if(last==0)
Definition: sparse_int.h:34
#define BZ_M_IDLE
#define BZ_FINISH_OK
Definition: bzlib.h:37
UInt32 avail_in_expect
Int32 numZ
Int32 mode
void * state
Definition: bzlib.h:61
#define BZ_M_FLUSHING
#define BZ_M_RUNNING
#define BZ_FLUSH_OK
Definition: bzlib.h:36
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN 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)
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
UInt32 * arr2
bz_stream * strm
UInt32 * arr1
#define BZ_OK
Definition: bzlib.h:34
if(last==0)
Definition: sparse_int.h:34
UInt32 * ftab
void * state
Definition: bzlib.h:61
ABC_NAMESPACE_HEADER_START BZ_EXTERN int BZ_API() BZ2_bzCompressInit ( bz_stream strm,
int  blockSize100k,
int  verbosity,
int  workFactor 
)

Definition at line 160 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 }
UInt16 * mtfv
#define BZFREE(ppp)
static int bz_config_ok(void)
Definition: bzlib.c:102
#define BZ_MEM_ERROR
Definition: bzlib.h:41
unsigned int total_in_hi32
Definition: bzlib.h:54
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
Int32 workFactor
UChar * zbits
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
unsigned int total_out_hi32
Definition: bzlib.h:59
static void prepare_new_block(EState *s)
Definition: bzlib.c:128
UInt32 * arr2
bz_stream * strm
#define BZ_S_INPUT
#define BZALLOC(nnn)
#define BZ_N_OVERSHOOT
UInt32 combinedCRC
Int32 verbosity
unsigned int total_in_lo32
Definition: bzlib.h:53
UInt32 * arr1
unsigned int total_out_lo32
Definition: bzlib.h:58
#define BZ_OK
Definition: bzlib.h:34
Int32 blockNo
unsigned char UChar
Definition: bzlib_private.h:45
Int32 nblockMAX
unsigned int UInt32
Definition: bzlib_private.h:47
#define BZ_CONFIG_ERROR
Definition: bzlib.h:47
static void * default_bzalloc(void *opaque, Int32 items, Int32 size)
Definition: bzlib.c:113
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
UInt32 * ftab
Int32 mode
void * state
Definition: bzlib.h:61
#define BZ_M_RUNNING
int Int32
Definition: bzlib_private.h:46
Int32 blockSize100k
static void default_bzfree(void *opaque, void *addr)
Definition: bzlib.c:120
UInt32 * ptr
UChar * block
static void init_RL(EState *s)
Definition: bzlib.c:142
unsigned short UInt16
Definition: bzlib_private.h:49
Int32 state
BZ_EXTERN 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,
839  s->calculatedBlockCRC );
840  if (s->verbosity >= 2) VPrintf0 ( "]" );
841  if (s->calculatedBlockCRC != s->storedBlockCRC)
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 }
UInt32 storedBlockCRC
Int32 state_out_len
#define BZ_X_MAGIC_1
#define BZ_FINALISE_CRC(crcVar)
bz_stream * strm
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
UInt32 calculatedBlockCRC
Int32 state
Bool smallDecompress
#define VPrintf2(zf, za1, za2)
Definition: bzlib_private.h:79
unsigned char Bool
Definition: bzlib_private.h:44
#define AssertH(cond, errcode)
Definition: bzlib_private.h:61
static Bool unRLE_obuf_to_output_SMALL(DState *s)
Definition: bzlib.c:717
#define BZ_OK
Definition: bzlib.h:34
UInt32 storedCombinedCRC
#define BZ_X_OUTPUT
Int32 BZ2_decompress(DState *)
Definition: decompress.c:109
#define BZ_STREAM_END
Definition: bzlib.h:38
if(last==0)
Definition: sparse_int.h:34
static Bool unRLE_obuf_to_output_FAST(DState *s)
Definition: bzlib.c:547
void * state
Definition: bzlib.h:61
Int32 verbosity
#define VPrintf0(zf)
Definition: bzlib_private.h:75
#define BZ_X_BLKHDR_1
int Int32
Definition: bzlib_private.h:46
#define BZ_DATA_ERROR
Definition: bzlib.h:42
Int32 nblock_used
Int32 save_nblock
#define True
Definition: bzlib_private.h:51
UInt32 calculatedCombinedCRC
#define BZ_X_IDLE
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN 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 }
#define BZFREE(ppp)
UInt16 * ll16
bz_stream * strm
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
#define BZ_OK
Definition: bzlib.h:34
if(last==0)
Definition: sparse_int.h:34
void * state
Definition: bzlib.h:61
UChar * ll4
UInt32 * tt
BZ_EXTERN int BZ_API() BZ2_bzDecompressInit ( bz_stream strm,
int  verbosity,
int  small 
)

Definition at line 504 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;
526  s->calculatedCombinedCRC = 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 }
static int bz_config_ok(void)
Definition: bzlib.c:102
#define BZ_MEM_ERROR
Definition: bzlib.h:41
UInt16 * ll16
#define BZ_X_MAGIC_1
unsigned int total_in_hi32
Definition: bzlib.h:54
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
bz_stream * strm
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
unsigned int total_out_hi32
Definition: bzlib.h:59
Int32 state
Bool smallDecompress
unsigned char Bool
Definition: bzlib_private.h:44
#define BZALLOC(nnn)
Int32 bsLive
unsigned int total_in_lo32
Definition: bzlib.h:53
unsigned int total_out_lo32
Definition: bzlib.h:58
#define BZ_OK
Definition: bzlib.h:34
#define BZ_CONFIG_ERROR
Definition: bzlib.h:47
static void * default_bzalloc(void *opaque, Int32 items, Int32 size)
Definition: bzlib.c:113
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
void * state
Definition: bzlib.h:61
Int32 verbosity
UInt32 bsBuff
UChar * ll4
UInt32 * tt
static void default_bzfree(void *opaque, void *addr)
Definition: bzlib.c:120
UInt32 calculatedCombinedCRC
Int32 currBlockNo
BZ_EXTERN BZFILE* BZ_API() BZ2_bzdopen ( int  fd,
const char *  mode 
)

Definition at line 1481 of file bzlib.c.

1483 {
1484  return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1);
1485 }
static BZFILE * bzopen_or_bzdopen(const char *path, int fd, const char *mode, int open_mode)
Definition: bzlib.c:1395
BZ_EXTERN 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 }
static const char * bzerrorstrings[]
Definition: bzlib.c:1550
Definition: bzlib.c:903
BZ_EXTERN int BZ_API() BZ2_bzflush ( BZFILE b)

Definition at line 1517 of file bzlib.c.

1518 {
1519  /* do nothing now... */
1520  return 0;
1521 }
BZ_EXTERN const char* BZ_API() BZ2_bzlibVersion ( void  )

Definition at line 1377 of file bzlib.c.

1378 {
1379  return BZ_VERSION;
1380 }
#define BZ_VERSION
Definition: bzlib_private.h:41
BZ_EXTERN BZFILE* BZ_API() BZ2_bzopen ( const char *  path,
const char *  mode 
)

Definition at line 1472 of file bzlib.c.

1474 {
1475  return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0);
1476 }
static BZFILE * bzopen_or_bzdopen(const char *path, int fd, const char *mode, int open_mode)
Definition: bzlib.c:1395
BZ_EXTERN int BZ_API() BZ2_bzRead ( int *  bzerror,
BZFILE b,
void *  buf,
int  len 
)

Definition at line 1173 of file bzlib.c.

1177 {
1178  Int32 n, ret;
1179  bzFile* bzf = (bzFile*)b;
1180 
1181  BZ_SETERR(BZ_OK);
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 }
int BZ_API() BZ2_bzDecompress(bz_stream *strm)
Definition: bzlib.c:819
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
static Bool myfeof(FILE *f)
Definition: bzlib.c:917
Int32 bufN
Definition: bzlib.c:907
FILE * handle
Definition: bzlib.c:905
Char buf[BZ_MAX_UNUSED]
Definition: bzlib.c:906
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
#define BZ_STREAM_END
Definition: bzlib.h:38
unsigned char UChar
Definition: bzlib_private.h:45
int Int32
Definition: bzlib_private.h:46
#define BZ_UNEXPECTED_EOF
Definition: bzlib.h:45
bz_stream strm
Definition: bzlib.c:909
#define BZ_MAX_UNUSED
Definition: bzlib.h:140
unsigned int avail_out
Definition: bzlib.h:57
#define True
Definition: bzlib_private.h:51
#define BZ_IO_ERROR
Definition: bzlib.h:44
char * next_out
Definition: bzlib.h:56
char * next_in
Definition: bzlib.h:51
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN 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 }
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
#define BZ_STREAM_END
Definition: bzlib.h:38
int BZ_API() BZ2_bzRead(int *bzerror, BZFILE *b, void *buf, int len)
Definition: bzlib.c:1173
BZ_EXTERN void BZ_API() BZ2_bzReadClose ( int *  bzerror,
BZFILE b 
)

Definition at line 1154 of file bzlib.c.

1155 {
1156  bzFile* bzf = (bzFile*)b;
1157 
1158  BZ_SETERR(BZ_OK);
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 }
VOID_HACK free()
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
int BZ_API() BZ2_bzDecompressEnd(bz_stream *strm)
Definition: bzlib.c:873
bz_stream strm
Definition: bzlib.c:909
Bool initialisedOk
Definition: bzlib.c:911
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN void BZ_API() BZ2_bzReadGetUnused ( int *  bzerror,
BZFILE b,
void **  unused,
int *  nUnused 
)

Definition at line 1233 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 
1246  BZ_SETERR(BZ_OK);
1247  *nUnused = bzf->strm.avail_in;
1248  *unused = bzf->strm.next_in;
1249 }
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
#define BZ_SETERR(eee)
Definition: bzlib.c:897
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
#define BZ_STREAM_END
Definition: bzlib.h:38
Int32 lastErr
Definition: bzlib.c:910
bz_stream strm
Definition: bzlib.c:909
char * next_in
Definition: bzlib.h:51
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN BZFILE* BZ_API() BZ2_bzReadOpen ( int *  bzerror,
FILE *  f,
int  verbosity,
int  small,
void *  unused,
int  nUnused 
)

Definition at line 1099 of file bzlib.c.

1105 {
1106  bzFile* bzf = NULL;
1107  int ret;
1108 
1109  BZ_SETERR(BZ_OK);
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 
1125  BZ_SETERR(BZ_OK);
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 }
char * malloc()
VOID_HACK free()
#define BZ_MEM_ERROR
Definition: bzlib.h:41
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
Int32 bufN
Definition: bzlib.c:907
FILE * handle
Definition: bzlib.c:905
Char buf[BZ_MAX_UNUSED]
Definition: bzlib.c:906
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
unsigned char UChar
Definition: bzlib_private.h:45
int BZ_API() BZ2_bzDecompressInit(bz_stream *strm, int verbosity, int small)
Definition: bzlib.c:504
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
bz_stream strm
Definition: bzlib.c:909
#define BZ_MAX_UNUSED
Definition: bzlib.h:140
void * opaque
Definition: bzlib.h:65
#define True
Definition: bzlib_private.h:51
#define BZ_IO_ERROR
Definition: bzlib.h:44
#define False
Definition: bzlib_private.h:52
Bool initialisedOk
Definition: bzlib.c:911
char * next_in
Definition: bzlib.h:51
BZ_EXTERN void BZ_API() BZ2_bzWrite ( int *  bzerror,
BZFILE b,
void *  buf,
int  len 
)

Definition at line 976 of file bzlib.c.

980 {
981  Int32 n, n2, ret;
982  bzFile* bzf = (bzFile*)b;
983 
984  BZ_SETERR(BZ_OK);
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 }
#define BZ_RUN_OK
Definition: bzlib.h:35
int BZ_API() BZ2_bzCompress(bz_stream *strm, int action)
Definition: bzlib.c:418
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
FILE * handle
Definition: bzlib.c:905
Char buf[BZ_MAX_UNUSED]
Definition: bzlib.c:906
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
#define BZ_RUN
Definition: bzlib.h:30
unsigned char UChar
Definition: bzlib_private.h:45
int Int32
Definition: bzlib_private.h:46
bz_stream strm
Definition: bzlib.c:909
#define BZ_MAX_UNUSED
Definition: bzlib.h:140
unsigned int avail_out
Definition: bzlib.h:57
#define True
Definition: bzlib_private.h:51
#define BZ_IO_ERROR
Definition: bzlib.h:44
char * next_out
Definition: bzlib.h:56
char * next_in
Definition: bzlib.h:51
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN 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
#define BZ_OK
Definition: bzlib.h:34
BZ_EXTERN void BZ_API() BZ2_bzWriteClose ( int *  bzerror,
BZFILE b,
int  abandon,
unsigned int *  nbytes_in,
unsigned int *  nbytes_out 
)

Definition at line 1021 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
BZ_EXTERN 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 1033 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) {
1058  bzf->strm.avail_out = BZ_MAX_UNUSED;
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 
1091  BZ_SETERR(BZ_OK);
1092  BZ2_bzCompressEnd ( &(bzf->strm) );
1093  free ( bzf );
1094 }
VOID_HACK free()
unsigned int total_in_hi32
Definition: bzlib.h:54
int BZ_API() BZ2_bzCompress(bz_stream *strm, int action)
Definition: bzlib.c:418
unsigned int total_out_hi32
Definition: bzlib.h:59
#define BZ_FINISH
Definition: bzlib.h:32
FILE * handle
Definition: bzlib.c:905
int BZ_API() BZ2_bzCompressEnd(bz_stream *strm)
Definition: bzlib.c:479
Char buf[BZ_MAX_UNUSED]
Definition: bzlib.c:906
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
unsigned int total_in_lo32
Definition: bzlib.h:53
unsigned int total_out_lo32
Definition: bzlib.h:58
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
#define BZ_STREAM_END
Definition: bzlib.h:38
unsigned char UChar
Definition: bzlib_private.h:45
Int32 lastErr
Definition: bzlib.c:910
#define BZ_FINISH_OK
Definition: bzlib.h:37
int Int32
Definition: bzlib_private.h:46
bz_stream strm
Definition: bzlib.c:909
#define BZ_MAX_UNUSED
Definition: bzlib.h:140
unsigned int avail_out
Definition: bzlib.h:57
#define True
Definition: bzlib_private.h:51
#define BZ_IO_ERROR
Definition: bzlib.h:44
char * next_out
Definition: bzlib.h:56
#define BZ_SEQUENCE_ERROR
Definition: bzlib.h:39
BZ_EXTERN BZFILE* BZ_API() BZ2_bzWriteOpen ( int *  bzerror,
FILE *  f,
int  blockSize100k,
int  verbosity,
int  workFactor 
)

Definition at line 928 of file bzlib.c.

933 {
934  Int32 ret;
935  bzFile* bzf = NULL;
936 
937  BZ_SETERR(BZ_OK);
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 
952  BZ_SETERR(BZ_OK);
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 }
char * malloc()
VOID_HACK free()
#define BZ_MEM_ERROR
Definition: bzlib.h:41
void *(* bzalloc)(void *, int, int)
Definition: bzlib.h:63
unsigned int avail_in
Definition: bzlib.h:52
#define BZ_PARAM_ERROR
Definition: bzlib.h:40
Int32 bufN
Definition: bzlib.c:907
FILE * handle
Definition: bzlib.c:905
Bool writing
Definition: bzlib.c:908
#define BZ_SETERR(eee)
Definition: bzlib.c:897
int BZ_API() BZ2_bzCompressInit(bz_stream *strm, int blockSize100k, int verbosity, int workFactor)
Definition: bzlib.c:160
#define BZ_OK
Definition: bzlib.h:34
Definition: bzlib.c:903
void(* bzfree)(void *, void *)
Definition: bzlib.h:64
int Int32
Definition: bzlib_private.h:46
bz_stream strm
Definition: bzlib.c:909
void * opaque
Definition: bzlib.h:65
#define True
Definition: bzlib_private.h:51
#define BZ_IO_ERROR
Definition: bzlib.h:44
#define False
Definition: bzlib_private.h:52
Bool initialisedOk
Definition: bzlib.c:911