Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions
bzlib.h File Reference
#include <stdio.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  bz_stream

Defines

#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

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)

Define Documentation

#define BZ_API (   func)    func

Definition at line 133 of file bzlib.h.

#define BZ_CONFIG_ERROR   (-9)

Definition at line 86 of file bzlib.h.

#define BZ_DATA_ERROR   (-4)

Definition at line 81 of file bzlib.h.

Definition at line 82 of file bzlib.h.

Definition at line 110 of file bzlib.h.

#define BZ_EXTERN   extern

Definition at line 134 of file bzlib.h.

#define BZ_FINISH   2

Definition at line 71 of file bzlib.h.

Definition at line 76 of file bzlib.h.

#define BZ_FLUSH   1

Definition at line 70 of file bzlib.h.

Definition at line 75 of file bzlib.h.

#define BZ_IO_ERROR   (-6)

Definition at line 83 of file bzlib.h.

#define BZ_MAX_UNUSED   5000

Definition at line 175 of file bzlib.h.

#define BZ_MEM_ERROR   (-3)

Definition at line 80 of file bzlib.h.

#define BZ_OK   0

Definition at line 73 of file bzlib.h.

#define BZ_OUTBUFF_FULL   (-8)

Definition at line 85 of file bzlib.h.

#define BZ_PARAM_ERROR   (-2)

Definition at line 79 of file bzlib.h.

#define BZ_RUN   0

Definition at line 69 of file bzlib.h.

#define BZ_RUN_OK   1

Definition at line 74 of file bzlib.h.

Definition at line 78 of file bzlib.h.

Definition at line 77 of file bzlib.h.

Definition at line 84 of file bzlib.h.


Typedef Documentation

typedef void BZFILE

Definition at line 177 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 1292 of file bzlib.c.

{
   bz_stream strm;
   int ret;

   if (dest == NULL || destLen == NULL || 
       source == NULL ||
       blockSize100k < 1 || blockSize100k > 9 ||
       verbosity < 0 || verbosity > 4 ||
       workFactor < 0 || workFactor > 250) 
      return BZ_PARAM_ERROR;

   if (workFactor == 0) workFactor = 30;
   strm.bzalloc = NULL;
   strm.bzfree = NULL;
   strm.opaque = NULL;
   ret = BZ2_bzCompressInit ( &strm, blockSize100k, 
                              verbosity, workFactor );
   if (ret != BZ_OK) return ret;

   strm.next_in = source;
   strm.next_out = dest;
   strm.avail_in = sourceLen;
   strm.avail_out = *destLen;

   ret = BZ2_bzCompress ( &strm, BZ_FINISH );
   if (ret == BZ_FINISH_OK) goto output_overflow;
   if (ret != BZ_STREAM_END) goto errhandler;

   /* normal termination */
   *destLen -= strm.avail_out;   
   BZ2_bzCompressEnd ( &strm );
   return BZ_OK;

   output_overflow:
   BZ2_bzCompressEnd ( &strm );
   return BZ_OUTBUFF_FULL;

   errhandler:
   BZ2_bzCompressEnd ( &strm );
   return ret;
}

Here is the call graph for this function:

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

Definition at line 1344 of file bzlib.c.

{
   bz_stream strm;
   int ret;

   if (dest == NULL || destLen == NULL || 
       source == NULL ||
       (small != 0 && small != 1) ||
       verbosity < 0 || verbosity > 4) 
          return BZ_PARAM_ERROR;

   strm.bzalloc = NULL;
   strm.bzfree = NULL;
   strm.opaque = NULL;
   ret = BZ2_bzDecompressInit ( &strm, verbosity, small );
   if (ret != BZ_OK) return ret;

   strm.next_in = source;
   strm.next_out = dest;
   strm.avail_in = sourceLen;
   strm.avail_out = *destLen;

   ret = BZ2_bzDecompress ( &strm );
   if (ret == BZ_OK) goto output_overflow_or_eof;
   if (ret != BZ_STREAM_END) goto errhandler;

   /* normal termination */
   *destLen -= strm.avail_out;
   BZ2_bzDecompressEnd ( &strm );
   return BZ_OK;

   output_overflow_or_eof:
   if (strm.avail_out > 0) {
      BZ2_bzDecompressEnd ( &strm );
      return BZ_UNEXPECTED_EOF;
   } else {
      BZ2_bzDecompressEnd ( &strm );
      return BZ_OUTBUFF_FULL;
   };      

   errhandler:
   BZ2_bzDecompressEnd ( &strm );
   return ret; 
}

Here is the call graph for this function:

Definition at line 1559 of file bzlib.c.

{
   int bzerr;
   FILE *fp = ((bzFile *)b)->handle;
   
   if (b==NULL) {return;}
   if(((bzFile*)b)->writing){
      BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL);
      if(bzerr != BZ_OK){
         BZ2_bzWriteClose(NULL,b,1,NULL,NULL);
      }
   }else{
      BZ2_bzReadClose(&bzerr,b);
   }
   if(fp!=stdin && fp!=stdout){
      fclose(fp);
   }
}

Here is the call graph for this function:

BZ_EXTERN int BZ_API() BZ2_bzCompress ( bz_stream strm,
int  action 
)

Definition at line 452 of file bzlib.c.

{
   Bool progress;
   EState* s;
   if (strm == NULL) return BZ_PARAM_ERROR;
   s = strm->state;
   if (s == NULL) return BZ_PARAM_ERROR;
   if (s->strm != strm) return BZ_PARAM_ERROR;

   preswitch:
   switch (s->mode) {

      case BZ_M_IDLE:
         return BZ_SEQUENCE_ERROR;

      case BZ_M_RUNNING:
         if (action == BZ_RUN) {
            progress = handle_compress ( strm );
            return progress ? BZ_RUN_OK : BZ_PARAM_ERROR;
         } 
         else
        if (action == BZ_FLUSH) {
            s->avail_in_expect = strm->avail_in;
            s->mode = BZ_M_FLUSHING;
            goto preswitch;
         }
         else
         if (action == BZ_FINISH) {
            s->avail_in_expect = strm->avail_in;
            s->mode = BZ_M_FINISHING;
            goto preswitch;
         }
         else 
            return BZ_PARAM_ERROR;

      case BZ_M_FLUSHING:
         if (action != BZ_FLUSH) return BZ_SEQUENCE_ERROR;
         if (s->avail_in_expect != s->strm->avail_in) 
            return BZ_SEQUENCE_ERROR;
         progress = handle_compress ( strm );
         if (s->avail_in_expect > 0 || !isempty_RL(s) ||
             s->state_out_pos < s->numZ) return BZ_FLUSH_OK;
         s->mode = BZ_M_RUNNING;
         return BZ_RUN_OK;

      case BZ_M_FINISHING:
         if (action != BZ_FINISH) return BZ_SEQUENCE_ERROR;
         if (s->avail_in_expect != s->strm->avail_in) 
            return BZ_SEQUENCE_ERROR;
         progress = handle_compress ( strm );
         if (!progress) return BZ_SEQUENCE_ERROR;
         if (s->avail_in_expect > 0 || !isempty_RL(s) ||
             s->state_out_pos < s->numZ) return BZ_FINISH_OK;
         s->mode = BZ_M_IDLE;
         return BZ_STREAM_END;
   }
   return BZ_OK; /*--not reached--*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 513 of file bzlib.c.

{
   EState* s;
   if (strm == NULL) return BZ_PARAM_ERROR;
   s = strm->state;
   if (s == NULL) return BZ_PARAM_ERROR;
   if (s->strm != strm) return BZ_PARAM_ERROR;

   if (s->arr1 != NULL) BZFREE(s->arr1);
   if (s->arr2 != NULL) BZFREE(s->arr2);
   if (s->ftab != NULL) BZFREE(s->ftab);
   BZFREE(strm->state);

   strm->state = NULL;   

   return BZ_OK;
}

Here is the caller graph for this function:

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

Definition at line 194 of file bzlib.c.

{
   Int32   n;
   EState* s;

   if (!bz_config_ok()) return BZ_CONFIG_ERROR;

   if (strm == NULL || 
       blockSize100k < 1 || blockSize100k > 9 ||
       workFactor < 0 || workFactor > 250)
     return BZ_PARAM_ERROR;

   if (workFactor == 0) workFactor = 30;
   if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
   if (strm->bzfree == NULL) strm->bzfree = default_bzfree;

   s = BZALLOC( sizeof(EState) );
   if (s == NULL) return BZ_MEM_ERROR;
   s->strm = strm;

   s->arr1 = NULL;
   s->arr2 = NULL;
   s->ftab = NULL;

   n       = 100000 * blockSize100k;
   s->arr1 = BZALLOC( n                  * sizeof(UInt32) );
   s->arr2 = BZALLOC( (n+BZ_N_OVERSHOOT) * sizeof(UInt32) );
   s->ftab = BZALLOC( 65537              * sizeof(UInt32) );

   if (s->arr1 == NULL || s->arr2 == NULL || s->ftab == NULL) {
      if (s->arr1 != NULL) BZFREE(s->arr1);
      if (s->arr2 != NULL) BZFREE(s->arr2);
      if (s->ftab != NULL) BZFREE(s->ftab);
      if (s       != NULL) BZFREE(s);
      return BZ_MEM_ERROR;
   }

   s->blockNo           = 0;
   s->state             = BZ_S_INPUT;
   s->mode              = BZ_M_RUNNING;
   s->combinedCRC       = 0;
   s->blockSize100k     = blockSize100k;
   s->nblockMAX         = 100000 * blockSize100k - 19;
   s->verbosity         = verbosity;
   s->workFactor        = workFactor;

   s->block             = (UChar*)s->arr2;
   s->mtfv              = (UInt16*)s->arr1;
   s->zbits             = NULL;
   s->ptr               = (UInt32*)s->arr1;

   strm->state          = s;
   strm->total_in_lo32  = 0;
   strm->total_in_hi32  = 0;
   strm->total_out_lo32 = 0;
   strm->total_out_hi32 = 0;
   init_RL ( s );
   prepare_new_block ( s );
   return BZ_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 852 of file bzlib.c.

{
   Bool    corrupt;
   DState* s;
   if (strm == NULL) return BZ_PARAM_ERROR;
   s = strm->state;
   if (s == NULL) return BZ_PARAM_ERROR;
   if (s->strm != strm) return BZ_PARAM_ERROR;

   while (True) {
      if (s->state == BZ_X_IDLE) return BZ_SEQUENCE_ERROR;
      if (s->state == BZ_X_OUTPUT) {
         if (s->smallDecompress)
            corrupt = unRLE_obuf_to_output_SMALL ( s ); else
            corrupt = unRLE_obuf_to_output_FAST  ( s );
         if (corrupt) return BZ_DATA_ERROR;
         if (s->nblock_used == s->save_nblock+1 && s->state_out_len == 0) {
            BZ_FINALISE_CRC ( s->calculatedBlockCRC );
            if (s->verbosity >= 3) 
               VPrintf2 ( " {0x%08x, 0x%08x}", s->storedBlockCRC, 
                          s->calculatedBlockCRC );
            if (s->verbosity >= 2) VPrintf0 ( "]" );
            if (s->calculatedBlockCRC != s->storedBlockCRC)
               return BZ_DATA_ERROR;
            s->calculatedCombinedCRC 
               = (s->calculatedCombinedCRC << 1) | 
                    (s->calculatedCombinedCRC >> 31);
            s->calculatedCombinedCRC ^= s->calculatedBlockCRC;
            s->state = BZ_X_BLKHDR_1;
         } else {
            return BZ_OK;
         }
      }
      if (s->state >= BZ_X_MAGIC_1) {
         Int32 r = BZ2_decompress ( s );
         if (r == BZ_STREAM_END) {
            if (s->verbosity >= 3)
               VPrintf2 ( "\n    combined CRCs: stored = 0x%08x, computed = 0x%08x", 
                          s->storedCombinedCRC, s->calculatedCombinedCRC );
            if (s->calculatedCombinedCRC != s->storedCombinedCRC)
               return BZ_DATA_ERROR;
            return r;
         }
         if (s->state != BZ_X_OUTPUT) return r;
      }
   }

   AssertH ( 0, 6001 );

   return 0;  /*NOTREACHED*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 906 of file bzlib.c.

{
   DState* s;
   if (strm == NULL) return BZ_PARAM_ERROR;
   s = strm->state;
   if (s == NULL) return BZ_PARAM_ERROR;
   if (s->strm != strm) return BZ_PARAM_ERROR;

   if (s->tt   != NULL) BZFREE(s->tt);
   if (s->ll16 != NULL) BZFREE(s->ll16);
   if (s->ll4  != NULL) BZFREE(s->ll4);

   BZFREE(strm->state);
   strm->state = NULL;

   return BZ_OK;
}

Here is the caller graph for this function:

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

Definition at line 538 of file bzlib.c.

{
   DState* s;

   if (!bz_config_ok()) return BZ_CONFIG_ERROR;

   if (strm == NULL) return BZ_PARAM_ERROR;
   if (small != 0 && small != 1) return BZ_PARAM_ERROR;
   if (verbosity < 0 || verbosity > 4) return BZ_PARAM_ERROR;

   if (strm->bzalloc == NULL) strm->bzalloc = default_bzalloc;
   if (strm->bzfree == NULL) strm->bzfree = default_bzfree;

   s = BZALLOC( sizeof(DState) );
   if (s == NULL) return BZ_MEM_ERROR;
   s->strm                  = strm;
   strm->state              = s;
   s->state                 = BZ_X_MAGIC_1;
   s->bsLive                = 0;
   s->bsBuff                = 0;
   s->calculatedCombinedCRC = 0;
   strm->total_in_lo32      = 0;
   strm->total_in_hi32      = 0;
   strm->total_out_lo32     = 0;
   strm->total_out_hi32     = 0;
   s->smallDecompress       = (Bool)small;
   s->ll4                   = NULL;
   s->ll16                  = NULL;
   s->tt                    = NULL;
   s->currBlockNo           = 0;
   s->verbosity             = verbosity;

   return BZ_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1515 of file bzlib.c.

{
   return bzopen_or_bzdopen(NULL,fd,mode,/*bzdopen*/1);
}

Here is the call graph for this function:

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

Definition at line 1603 of file bzlib.c.

{
   int err = ((bzFile *)b)->lastErr;

   if(err>0) err = 0;
   *errnum = err;
   return bzerrorstrings[err*-1];
}

Definition at line 1551 of file bzlib.c.

{
   /* do nothing now... */
   return 0;
}

Definition at line 1411 of file bzlib.c.

{
   return BZ_VERSION;
}

Here is the caller graph for this function:

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

Definition at line 1506 of file bzlib.c.

{
   return bzopen_or_bzdopen(path,-1,mode,/*bzopen*/0);
}

Here is the call graph for this function:

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

Definition at line 1206 of file bzlib.c.

{
   Int32   n, ret;
   bzFile* bzf = (bzFile*)b;

   BZ_SETERR(BZ_OK);

   if (bzf == NULL || buf == NULL || len < 0)
      { BZ_SETERR(BZ_PARAM_ERROR); return 0; };

   if (bzf->writing)
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return 0; };

   if (len == 0)
      { BZ_SETERR(BZ_OK); return 0; };

   bzf->strm.avail_out = len;
   bzf->strm.next_out = buf;

   while (True) {

      if (ferror(bzf->handle)) 
         { BZ_SETERR(BZ_IO_ERROR); return 0; };

      if (bzf->strm.avail_in == 0 && !myfeof(bzf->handle)) {
         n = fread ( bzf->buf, sizeof(UChar), 
                     BZ_MAX_UNUSED, bzf->handle );
         if (ferror(bzf->handle))
            { BZ_SETERR(BZ_IO_ERROR); return 0; };
         bzf->bufN = n;
         bzf->strm.avail_in = bzf->bufN;
         bzf->strm.next_in = bzf->buf;
      }

      ret = BZ2_bzDecompress ( &(bzf->strm) );

      if (ret != BZ_OK && ret != BZ_STREAM_END)
         { BZ_SETERR(ret); return 0; };

      if (ret == BZ_OK && myfeof(bzf->handle) && 
          bzf->strm.avail_in == 0 && bzf->strm.avail_out > 0)
         { BZ_SETERR(BZ_UNEXPECTED_EOF); return 0; };

      if (ret == BZ_STREAM_END)
         { BZ_SETERR(BZ_STREAM_END);
           return len - bzf->strm.avail_out; };
      if (bzf->strm.avail_out == 0)
         { BZ_SETERR(BZ_OK); return len; };
      
   }

   return 0; /*not reached*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1523 of file bzlib.c.

{
   int bzerr, nread;
   if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0;
   nread = BZ2_bzRead(&bzerr,b,buf,len);
   if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) {
      return nread;
   } else {
      return -1;
   }
}

Here is the call graph for this function:

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

Definition at line 1187 of file bzlib.c.

{
   bzFile* bzf = (bzFile*)b;

   BZ_SETERR(BZ_OK);
   if (bzf == NULL)
      { BZ_SETERR(BZ_OK); return; };

   if (bzf->writing)
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };

   if (bzf->initialisedOk)
      (void)BZ2_bzDecompressEnd ( &(bzf->strm) );
   free ( bzf );
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1266 of file bzlib.c.

{
   bzFile* bzf = (bzFile*)b;
   if (bzf == NULL)
      { BZ_SETERR(BZ_PARAM_ERROR); return; };
   if (bzf->lastErr != BZ_STREAM_END)
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
   if (unused == NULL || nUnused == NULL)
      { BZ_SETERR(BZ_PARAM_ERROR); return; };

   BZ_SETERR(BZ_OK);
   *nUnused = bzf->strm.avail_in;
   *unused = bzf->strm.next_in;
}
BZ_EXTERN BZFILE* BZ_API() BZ2_bzReadOpen ( int bzerror,
FILE f,
int  verbosity,
int  small,
void unused,
int  nUnused 
)

Definition at line 1132 of file bzlib.c.

{
   bzFile* bzf = NULL;
   int     ret;

   BZ_SETERR(BZ_OK);

   if (f == NULL || 
       (small != 0 && small != 1) ||
       (verbosity < 0 || verbosity > 4) ||
       (unused == NULL && nUnused != 0) ||
       (unused != NULL && (nUnused < 0 || nUnused > BZ_MAX_UNUSED)))
      { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };

   if (ferror(f))
      { BZ_SETERR(BZ_IO_ERROR); return NULL; };

   bzf = malloc ( sizeof(bzFile) );
   if (bzf == NULL) 
      { BZ_SETERR(BZ_MEM_ERROR); return NULL; };

   BZ_SETERR(BZ_OK);

   bzf->initialisedOk = False;
   bzf->handle        = f;
   bzf->bufN          = 0;
   bzf->writing       = False;
   bzf->strm.bzalloc  = NULL;
   bzf->strm.bzfree   = NULL;
   bzf->strm.opaque   = NULL;
   
   while (nUnused > 0) {
      bzf->buf[bzf->bufN] = *((UChar*)(unused)); bzf->bufN++;
      unused = ((void*)( 1 + ((UChar*)(unused))  ));
      nUnused--;
   }

   ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small );
   if (ret != BZ_OK)
      { BZ_SETERR(ret); free(bzf); return NULL; };

   bzf->strm.avail_in = bzf->bufN;
   bzf->strm.next_in  = bzf->buf;

   bzf->initialisedOk = True;
   return bzf;   
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1009 of file bzlib.c.

{
   Int32 n, n2, ret;
   bzFile* bzf = (bzFile*)b;

   BZ_SETERR(BZ_OK);
   if (bzf == NULL || buf == NULL || len < 0)
      { BZ_SETERR(BZ_PARAM_ERROR); return; };
   if (!(bzf->writing))
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
   if (ferror(bzf->handle))
      { BZ_SETERR(BZ_IO_ERROR); return; };

   if (len == 0)
      { BZ_SETERR(BZ_OK); return; };

   bzf->strm.avail_in = len;
   bzf->strm.next_in  = buf;

   while (True) {
      bzf->strm.avail_out = BZ_MAX_UNUSED;
      bzf->strm.next_out = bzf->buf;
      ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN );
      if (ret != BZ_RUN_OK)
         { BZ_SETERR(ret); return; };

      if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
         n = BZ_MAX_UNUSED - bzf->strm.avail_out;
         n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), 
                       n, bzf->handle );
         if (n != n2 || ferror(bzf->handle))
            { BZ_SETERR(BZ_IO_ERROR); return; };
      }

      if (bzf->strm.avail_in == 0)
         { BZ_SETERR(BZ_OK); return; };
   }
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1537 of file bzlib.c.

{
   int bzerr;

   BZ2_bzWrite(&bzerr,b,buf,len);
   if(bzerr == BZ_OK){
      return len;
   }else{
      return -1;
   }
}

Here is the call graph for this function:

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

Definition at line 1054 of file bzlib.c.

{
   BZ2_bzWriteClose64 ( bzerror, b, abandon, 
                        nbytes_in, NULL, nbytes_out, NULL );
}

Here is the call graph for this function:

Here is the caller graph for this function:

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 1066 of file bzlib.c.

{
   Int32   n, n2, ret;
   bzFile* bzf = (bzFile*)b;

   if (bzf == NULL)
      { BZ_SETERR(BZ_OK); return; };
   if (!(bzf->writing))
      { BZ_SETERR(BZ_SEQUENCE_ERROR); return; };
   if (ferror(bzf->handle))
      { BZ_SETERR(BZ_IO_ERROR); return; };

   if (nbytes_in_lo32 != NULL) *nbytes_in_lo32 = 0;
   if (nbytes_in_hi32 != NULL) *nbytes_in_hi32 = 0;
   if (nbytes_out_lo32 != NULL) *nbytes_out_lo32 = 0;
   if (nbytes_out_hi32 != NULL) *nbytes_out_hi32 = 0;

   if ((!abandon) && bzf->lastErr == BZ_OK) {
      while (True) {
         bzf->strm.avail_out = BZ_MAX_UNUSED;
         bzf->strm.next_out = bzf->buf;
         ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH );
         if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
            { BZ_SETERR(ret); return; };

         if (bzf->strm.avail_out < BZ_MAX_UNUSED) {
            n = BZ_MAX_UNUSED - bzf->strm.avail_out;
            n2 = fwrite ( (void*)(bzf->buf), sizeof(UChar), 
                          n, bzf->handle );
            if (n != n2 || ferror(bzf->handle))
               { BZ_SETERR(BZ_IO_ERROR); return; };
         }

         if (ret == BZ_STREAM_END) break;
      }
   }

   if ( !abandon && !ferror ( bzf->handle ) ) {
      fflush ( bzf->handle );
      if (ferror(bzf->handle))
         { BZ_SETERR(BZ_IO_ERROR); return; };
   }

   if (nbytes_in_lo32 != NULL)
      *nbytes_in_lo32 = bzf->strm.total_in_lo32;
   if (nbytes_in_hi32 != NULL)
      *nbytes_in_hi32 = bzf->strm.total_in_hi32;
   if (nbytes_out_lo32 != NULL)
      *nbytes_out_lo32 = bzf->strm.total_out_lo32;
   if (nbytes_out_hi32 != NULL)
      *nbytes_out_hi32 = bzf->strm.total_out_hi32;

   BZ_SETERR(BZ_OK);
   BZ2_bzCompressEnd ( &(bzf->strm) );
   free ( bzf );
}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 961 of file bzlib.c.

{
   Int32   ret;
   bzFile* bzf = NULL;

   BZ_SETERR(BZ_OK);

   if (f == NULL ||
       (blockSize100k < 1 || blockSize100k > 9) ||
       (workFactor < 0 || workFactor > 250) ||
       (verbosity < 0 || verbosity > 4))
      { BZ_SETERR(BZ_PARAM_ERROR); return NULL; };

   if (ferror(f))
      { BZ_SETERR(BZ_IO_ERROR); return NULL; };

   bzf = malloc ( sizeof(bzFile) );
   if (bzf == NULL)
      { BZ_SETERR(BZ_MEM_ERROR); return NULL; };

   BZ_SETERR(BZ_OK);
   bzf->initialisedOk = False;
   bzf->bufN          = 0;
   bzf->handle        = f;
   bzf->writing       = True;
   bzf->strm.bzalloc  = NULL;
   bzf->strm.bzfree   = NULL;
   bzf->strm.opaque   = NULL;

   if (workFactor == 0) workFactor = 30;
   ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k, 
                              verbosity, workFactor );
   if (ret != BZ_OK)
      { BZ_SETERR(ret); free(bzf); return NULL; };

   bzf->strm.avail_in = 0;
   bzf->initialisedOk = True;
   return bzf;   
}

Here is the call graph for this function:

Here is the caller graph for this function: