From 795b859eee96c700e8f3c3fe68e6a9a39d95797c Mon Sep 17 00:00:00 2001 From: Julian Seward Date: Sat, 24 Jun 2000 22:13:13 +0200 Subject: bzip2-1.0.1 --- bzlib.c | 248 +++++++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 152 insertions(+), 96 deletions(-) (limited to 'bzlib.c') diff --git a/bzlib.c b/bzlib.c index 24e8bd5..4a06d9f 100644 --- a/bzlib.c +++ b/bzlib.c @@ -8,7 +8,7 @@ This file is a part of bzip2 and/or libbzip2, a program and library for lossless, block-sorting data compression. - Copyright (C) 1996-1999 Julian R Seward. All rights reserved. + Copyright (C) 1996-2000 Julian R Seward. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions @@ -43,7 +43,7 @@ Julian Seward, Cambridge, UK. jseward@acm.org - bzip2/libbzip2 version 0.9.5 of 24 May 1999 + bzip2/libbzip2 version 1.0 of 21 March 2000 This program is based on (at least) the work of: Mike Burrows @@ -83,24 +83,36 @@ /*---------------------------------------------------*/ #ifndef BZ_NO_STDIO -void bz__AssertH__fail ( int errcode ) +void BZ2_bz__AssertH__fail ( int errcode ) { fprintf(stderr, - "\n\nbzip2/libbzip2, v0.9.5d: internal error number %d.\n" - "This is a bug in bzip2/libbzip2, v0.9.5d. Please report\n" - "it to me at: jseward@acm.org. If this happened when\n" - "you were using some program which uses libbzip2 as a\n" + "\n\nbzip2/libbzip2: internal error number %d.\n" + "This is a bug in bzip2/libbzip2, %s.\n" + "Please report it to me at: jseward@acm.org. If this happened\n" + "when you were using some program which uses libbzip2 as a\n" "component, you should also report this bug to the author(s)\n" "of that program. Please make an effort to report this bug;\n" "timely and accurate bug reports eventually lead to higher\n" - "quality software. Thanks. Julian Seward, 4 Sept 1999.\n\n", - errcode + "quality software. Thanks. Julian Seward, 21 March 2000.\n\n", + errcode, + BZ2_bzlibVersion() ); exit(3); } #endif +/*---------------------------------------------------*/ +static +int bz_config_ok ( void ) +{ + if (sizeof(int) != 4) return 0; + if (sizeof(short) != 2) return 0; + if (sizeof(char) != 1) return 0; + return 1; +} + + /*---------------------------------------------------*/ static void* default_bzalloc ( void* opaque, Int32 items, Int32 size ) @@ -149,7 +161,7 @@ Bool isempty_RL ( EState* s ) /*---------------------------------------------------*/ -int BZ_API(bzCompressInit) +int BZ_API(BZ2_bzCompressInit) ( bz_stream* strm, int blockSize100k, int verbosity, @@ -158,6 +170,8 @@ int BZ_API(bzCompressInit) Int32 n; EState* s; + if (!bz_config_ok()) return BZ_CONFIG_ERROR; + if (strm == NULL || blockSize100k < 1 || blockSize100k > 9 || workFactor < 0 || workFactor > 250) @@ -197,14 +211,16 @@ int BZ_API(bzCompressInit) s->verbosity = verbosity; s->workFactor = workFactor; - s->block = (UInt16*)s->arr2; + s->block = (UChar*)s->arr2; s->mtfv = (UInt16*)s->arr1; s->zbits = NULL; s->ptr = (UInt32*)s->arr1; strm->state = s; - strm->total_in = 0; - strm->total_out = 0; + 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; @@ -223,24 +239,24 @@ void add_pair_to_block ( EState* s ) s->inUse[s->state_in_ch] = True; switch (s->state_in_len) { case 1: - s->block[s->nblock] = (UInt16)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; break; case 2: - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; break; case 3: - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; break; default: s->inUse[s->state_in_len-4] = True; - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = (UInt16)ch; s->nblock++; - s->block[s->nblock] = ((UInt16)(s->state_in_len-4)); + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = (UChar)ch; s->nblock++; + s->block[s->nblock] = ((UChar)(s->state_in_len-4)); s->nblock++; break; } @@ -266,7 +282,7 @@ void flush_RL ( EState* s ) UChar ch = (UChar)(zs->state_in_ch); \ BZ_UPDATE_CRC( zs->blockCRC, ch ); \ zs->inUse[zs->state_in_ch] = True; \ - zs->block[zs->nblock] = (UInt16)ch; \ + zs->block[zs->nblock] = (UChar)ch; \ zs->nblock++; \ zs->state_in_ch = zchh; \ } \ @@ -302,7 +318,8 @@ Bool copy_input_until_stop ( EState* s ) ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); s->strm->next_in++; s->strm->avail_in--; - s->strm->total_in++; + s->strm->total_in_lo32++; + if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; } } else { @@ -319,7 +336,8 @@ Bool copy_input_until_stop ( EState* s ) ADD_CHAR_TO_BLOCK ( s, (UInt32)(*((UChar*)(s->strm->next_in))) ); s->strm->next_in++; s->strm->avail_in--; - s->strm->total_in++; + s->strm->total_in_lo32++; + if (s->strm->total_in_lo32 == 0) s->strm->total_in_hi32++; s->avail_in_expect--; } } @@ -346,8 +364,8 @@ Bool copy_output_until_stop ( EState* s ) s->state_out_pos++; s->strm->avail_out--; s->strm->next_out++; - s->strm->total_out++; - + s->strm->total_out_lo32++; + if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; } return progress_out; @@ -381,12 +399,12 @@ Bool handle_compress ( bz_stream* strm ) progress_in |= copy_input_until_stop ( s ); if (s->mode != BZ_M_RUNNING && s->avail_in_expect == 0) { flush_RL ( s ); - compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) ); + BZ2_compressBlock ( s, (Bool)(s->mode == BZ_M_FINISHING) ); s->state = BZ_S_OUTPUT; } else if (s->nblock >= s->nblockMAX) { - compressBlock ( s, False ); + BZ2_compressBlock ( s, False ); s->state = BZ_S_OUTPUT; } else @@ -402,7 +420,7 @@ Bool handle_compress ( bz_stream* strm ) /*---------------------------------------------------*/ -int BZ_API(bzCompress) ( bz_stream *strm, int action ) +int BZ_API(BZ2_bzCompress) ( bz_stream *strm, int action ) { Bool progress; EState* s; @@ -439,7 +457,8 @@ int BZ_API(bzCompress) ( bz_stream *strm, int action ) 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; + 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; @@ -448,7 +467,8 @@ int BZ_API(bzCompress) ( bz_stream *strm, int action ) 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; + 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) || @@ -461,7 +481,7 @@ int BZ_API(bzCompress) ( bz_stream *strm, int action ) /*---------------------------------------------------*/ -int BZ_API(bzCompressEnd) ( bz_stream *strm ) +int BZ_API(BZ2_bzCompressEnd) ( bz_stream *strm ) { EState* s; if (strm == NULL) return BZ_PARAM_ERROR; @@ -485,13 +505,15 @@ int BZ_API(bzCompressEnd) ( bz_stream *strm ) /*---------------------------------------------------*/ /*---------------------------------------------------*/ -int BZ_API(bzDecompressInit) +int BZ_API(BZ2_bzDecompressInit) ( bz_stream* strm, int verbosity, int small ) { 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; @@ -507,8 +529,10 @@ int BZ_API(bzDecompressInit) s->bsLive = 0; s->bsBuff = 0; s->calculatedCombinedCRC = 0; - strm->total_in = 0; - strm->total_out = 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; @@ -538,7 +562,8 @@ void unRLE_obuf_to_output_FAST ( DState* s ) s->state_out_len--; s->strm->next_out++; s->strm->avail_out--; - s->strm->total_out++; + s->strm->total_out_lo32++; + if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; } /* can a new run be started? */ @@ -585,8 +610,9 @@ void unRLE_obuf_to_output_FAST ( DState* s ) unsigned int cs_avail_out = s->strm->avail_out; /* end restore */ - UInt32 avail_out_INIT = cs_avail_out; - Int32 s_save_nblockPP = s->save_nblock+1; + UInt32 avail_out_INIT = cs_avail_out; + Int32 s_save_nblockPP = s->save_nblock+1; + unsigned int total_out_lo32_old; while (True) { @@ -640,7 +666,10 @@ void unRLE_obuf_to_output_FAST ( DState* s ) } return_notr: - s->strm->total_out += (avail_out_INIT - cs_avail_out); + total_out_lo32_old = s->strm->total_out_lo32; + s->strm->total_out_lo32 += (avail_out_INIT - cs_avail_out); + if (s->strm->total_out_lo32 < total_out_lo32_old) + s->strm->total_out_hi32++; /* save */ s->calculatedBlockCRC = c_calculatedBlockCRC; @@ -659,7 +688,7 @@ void unRLE_obuf_to_output_FAST ( DState* s ) /*---------------------------------------------------*/ -__inline__ Int32 indexIntoF ( Int32 indx, Int32 *cftab ) +__inline__ Int32 BZ2_indexIntoF ( Int32 indx, Int32 *cftab ) { Int32 nb, na, mid; nb = 0; @@ -691,7 +720,8 @@ void unRLE_obuf_to_output_SMALL ( DState* s ) s->state_out_len--; s->strm->next_out++; s->strm->avail_out--; - s->strm->total_out++; + s->strm->total_out_lo32++; + if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; } /* can a new run be started? */ @@ -736,7 +766,8 @@ void unRLE_obuf_to_output_SMALL ( DState* s ) s->state_out_len--; s->strm->next_out++; s->strm->avail_out--; - s->strm->total_out++; + s->strm->total_out_lo32++; + if (s->strm->total_out_lo32 == 0) s->strm->total_out_hi32++; } /* can a new run be started? */ @@ -768,7 +799,7 @@ void unRLE_obuf_to_output_SMALL ( DState* s ) /*---------------------------------------------------*/ -int BZ_API(bzDecompress) ( bz_stream *strm ) +int BZ_API(BZ2_bzDecompress) ( bz_stream *strm ) { DState* s; if (strm == NULL) return BZ_PARAM_ERROR; @@ -800,7 +831,7 @@ int BZ_API(bzDecompress) ( bz_stream *strm ) } } if (s->state >= BZ_X_MAGIC_1) { - Int32 r = decompress ( s ); + Int32 r = BZ2_decompress ( s ); if (r == BZ_STREAM_END) { if (s->verbosity >= 3) VPrintf2 ( "\n combined CRCs: stored = 0x%x, computed = 0x%x", @@ -820,7 +851,7 @@ int BZ_API(bzDecompress) ( bz_stream *strm ) /*---------------------------------------------------*/ -int BZ_API(bzDecompressEnd) ( bz_stream *strm ) +int BZ_API(BZ2_bzDecompressEnd) ( bz_stream *strm ) { DState* s; if (strm == NULL) return BZ_PARAM_ERROR; @@ -874,7 +905,7 @@ static Bool myfeof ( FILE* f ) /*---------------------------------------------------*/ -BZFILE* BZ_API(bzWriteOpen) +BZFILE* BZ_API(BZ2_bzWriteOpen) ( int* bzerror, FILE* f, int blockSize100k, @@ -909,8 +940,8 @@ BZFILE* BZ_API(bzWriteOpen) bzf->strm.opaque = NULL; if (workFactor == 0) workFactor = 30; - ret = bzCompressInit ( &(bzf->strm), blockSize100k, - verbosity, workFactor ); + ret = BZ2_bzCompressInit ( &(bzf->strm), blockSize100k, + verbosity, workFactor ); if (ret != BZ_OK) { BZ_SETERR(ret); free(bzf); return NULL; }; @@ -922,7 +953,7 @@ BZFILE* BZ_API(bzWriteOpen) /*---------------------------------------------------*/ -void BZ_API(bzWrite) +void BZ_API(BZ2_bzWrite) ( int* bzerror, BZFILE* b, void* buf, @@ -948,7 +979,7 @@ void BZ_API(bzWrite) while (True) { bzf->strm.avail_out = BZ_MAX_UNUSED; bzf->strm.next_out = bzf->buf; - ret = bzCompress ( &(bzf->strm), BZ_RUN ); + ret = BZ2_bzCompress ( &(bzf->strm), BZ_RUN ); if (ret != BZ_RUN_OK) { BZ_SETERR(ret); return; }; @@ -967,12 +998,26 @@ void BZ_API(bzWrite) /*---------------------------------------------------*/ -void BZ_API(bzWriteClose) +void BZ_API(BZ2_bzWriteClose) ( int* bzerror, BZFILE* b, int abandon, unsigned int* nbytes_in, unsigned int* nbytes_out ) +{ + BZ2_bzWriteClose64 ( bzerror, b, abandon, + nbytes_in, NULL, nbytes_out, NULL ); +} + + +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 ) { Int32 n, n2, ret; bzFile* bzf = (bzFile*)b; @@ -984,14 +1029,16 @@ void BZ_API(bzWriteClose) if (ferror(bzf->handle)) { BZ_SETERR(BZ_IO_ERROR); return; }; - if (nbytes_in != NULL) *nbytes_in = 0; - if (nbytes_out != NULL) *nbytes_out = 0; + 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 = bzCompress ( &(bzf->strm), BZ_FINISH ); + ret = BZ2_bzCompress ( &(bzf->strm), BZ_FINISH ); if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END) { BZ_SETERR(ret); return; }; @@ -1013,17 +1060,23 @@ void BZ_API(bzWriteClose) { BZ_SETERR(BZ_IO_ERROR); return; }; } - if (nbytes_in != NULL) *nbytes_in = bzf->strm.total_in; - if (nbytes_out != NULL) *nbytes_out = bzf->strm.total_out; + 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); - bzCompressEnd ( &(bzf->strm) ); + BZ2_bzCompressEnd ( &(bzf->strm) ); free ( bzf ); } /*---------------------------------------------------*/ -BZFILE* BZ_API(bzReadOpen) +BZFILE* BZ_API(BZ2_bzReadOpen) ( int* bzerror, FILE* f, int verbosity, @@ -1066,7 +1119,7 @@ BZFILE* BZ_API(bzReadOpen) nUnused--; } - ret = bzDecompressInit ( &(bzf->strm), verbosity, small ); + ret = BZ2_bzDecompressInit ( &(bzf->strm), verbosity, small ); if (ret != BZ_OK) { BZ_SETERR(ret); free(bzf); return NULL; }; @@ -1079,7 +1132,7 @@ BZFILE* BZ_API(bzReadOpen) /*---------------------------------------------------*/ -void BZ_API(bzReadClose) ( int *bzerror, BZFILE *b ) +void BZ_API(BZ2_bzReadClose) ( int *bzerror, BZFILE *b ) { bzFile* bzf = (bzFile*)b; @@ -1091,13 +1144,13 @@ void BZ_API(bzReadClose) ( int *bzerror, BZFILE *b ) { BZ_SETERR(BZ_SEQUENCE_ERROR); return; }; if (bzf->initialisedOk) - (void)bzDecompressEnd ( &(bzf->strm) ); + (void)BZ2_bzDecompressEnd ( &(bzf->strm) ); free ( bzf ); } /*---------------------------------------------------*/ -int BZ_API(bzRead) +int BZ_API(BZ2_bzRead) ( int* bzerror, BZFILE* b, void* buf, @@ -1135,7 +1188,7 @@ int BZ_API(bzRead) bzf->strm.next_in = bzf->buf; } - ret = bzDecompress ( &(bzf->strm) ); + ret = BZ2_bzDecompress ( &(bzf->strm) ); if (ret != BZ_OK && ret != BZ_STREAM_END) { BZ_SETERR(ret); return 0; }; @@ -1157,7 +1210,7 @@ int BZ_API(bzRead) /*---------------------------------------------------*/ -void BZ_API(bzReadGetUnused) +void BZ_API(BZ2_bzReadGetUnused) ( int* bzerror, BZFILE* b, void** unused, @@ -1183,7 +1236,7 @@ void BZ_API(bzReadGetUnused) /*---------------------------------------------------*/ /*---------------------------------------------------*/ -int BZ_API(bzBuffToBuffCompress) +int BZ_API(BZ2_bzBuffToBuffCompress) ( char* dest, unsigned int* destLen, char* source, @@ -1206,8 +1259,8 @@ int BZ_API(bzBuffToBuffCompress) strm.bzalloc = NULL; strm.bzfree = NULL; strm.opaque = NULL; - ret = bzCompressInit ( &strm, blockSize100k, - verbosity, workFactor ); + ret = BZ2_bzCompressInit ( &strm, blockSize100k, + verbosity, workFactor ); if (ret != BZ_OK) return ret; strm.next_in = source; @@ -1215,27 +1268,27 @@ int BZ_API(bzBuffToBuffCompress) strm.avail_in = sourceLen; strm.avail_out = *destLen; - ret = bzCompress ( &strm, BZ_FINISH ); + 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; - bzCompressEnd ( &strm ); + BZ2_bzCompressEnd ( &strm ); return BZ_OK; output_overflow: - bzCompressEnd ( &strm ); + BZ2_bzCompressEnd ( &strm ); return BZ_OUTBUFF_FULL; errhandler: - bzCompressEnd ( &strm ); + BZ2_bzCompressEnd ( &strm ); return ret; } /*---------------------------------------------------*/ -int BZ_API(bzBuffToBuffDecompress) +int BZ_API(BZ2_bzBuffToBuffDecompress) ( char* dest, unsigned int* destLen, char* source, @@ -1255,7 +1308,7 @@ int BZ_API(bzBuffToBuffDecompress) strm.bzalloc = NULL; strm.bzfree = NULL; strm.opaque = NULL; - ret = bzDecompressInit ( &strm, verbosity, small ); + ret = BZ2_bzDecompressInit ( &strm, verbosity, small ); if (ret != BZ_OK) return ret; strm.next_in = source; @@ -1263,26 +1316,26 @@ int BZ_API(bzBuffToBuffDecompress) strm.avail_in = sourceLen; strm.avail_out = *destLen; - ret = bzDecompress ( &strm ); + 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; - bzDecompressEnd ( &strm ); + BZ2_bzDecompressEnd ( &strm ); return BZ_OK; output_overflow_or_eof: if (strm.avail_out > 0) { - bzDecompressEnd ( &strm ); + BZ2_bzDecompressEnd ( &strm ); return BZ_UNEXPECTED_EOF; } else { - bzDecompressEnd ( &strm ); + BZ2_bzDecompressEnd ( &strm ); return BZ_OUTBUFF_FULL; }; errhandler: - bzDecompressEnd ( &strm ); + BZ2_bzDecompressEnd ( &strm ); return ret; } @@ -1303,7 +1356,7 @@ int BZ_API(bzBuffToBuffDecompress) /*-- return version like "0.9.0c". --*/ -const char * BZ_API(bzlibVersion)(void) +const char * BZ_API(BZ2_bzlibVersion)(void) { return BZ_VERSION; } @@ -1377,9 +1430,11 @@ BZFILE * bzopen_or_bzdopen /* Guard against total chaos and anarchy -- JRS */ if (blockSize100k < 1) blockSize100k = 1; if (blockSize100k > 9) blockSize100k = 9; - bzfp = bzWriteOpen(&bzerr,fp,blockSize100k,verbosity,workFactor); + bzfp = BZ2_bzWriteOpen(&bzerr,fp,blockSize100k, + verbosity,workFactor); } else { - bzfp = bzReadOpen(&bzerr,fp,verbosity,smallMode,unused,nUnused); + bzfp = BZ2_bzReadOpen(&bzerr,fp,verbosity,smallMode, + unused,nUnused); } if (bzfp == NULL) { if (fp != stdin && fp != stdout) fclose(fp); @@ -1395,7 +1450,7 @@ BZFILE * bzopen_or_bzdopen ex) bzopen("file","w9") case path="" or NULL => use stdin or stdout. --*/ -BZFILE * BZ_API(bzopen) +BZFILE * BZ_API(BZ2_bzopen) ( const char *path, const char *mode ) { @@ -1404,7 +1459,7 @@ BZFILE * BZ_API(bzopen) /*---------------------------------------------------*/ -BZFILE * BZ_API(bzdopen) +BZFILE * BZ_API(BZ2_bzdopen) ( int fd, const char *mode ) { @@ -1413,11 +1468,11 @@ BZFILE * BZ_API(bzdopen) /*---------------------------------------------------*/ -int BZ_API(bzread) (BZFILE* b, void* buf, int len ) +int BZ_API(BZ2_bzread) (BZFILE* b, void* buf, int len ) { int bzerr, nread; if (((bzFile*)b)->lastErr == BZ_STREAM_END) return 0; - nread = bzRead(&bzerr,b,buf,len); + nread = BZ2_bzRead(&bzerr,b,buf,len); if (bzerr == BZ_OK || bzerr == BZ_STREAM_END) { return nread; } else { @@ -1427,11 +1482,11 @@ int BZ_API(bzread) (BZFILE* b, void* buf, int len ) /*---------------------------------------------------*/ -int BZ_API(bzwrite) (BZFILE* b, void* buf, int len ) +int BZ_API(BZ2_bzwrite) (BZFILE* b, void* buf, int len ) { int bzerr; - bzWrite(&bzerr,b,buf,len); + BZ2_bzWrite(&bzerr,b,buf,len); if(bzerr == BZ_OK){ return len; }else{ @@ -1441,7 +1496,7 @@ int BZ_API(bzwrite) (BZFILE* b, void* buf, int len ) /*---------------------------------------------------*/ -int BZ_API(bzflush) (BZFILE *b) +int BZ_API(BZ2_bzflush) (BZFILE *b) { /* do nothing now... */ return 0; @@ -1449,19 +1504,19 @@ int BZ_API(bzflush) (BZFILE *b) /*---------------------------------------------------*/ -void BZ_API(bzclose) (BZFILE* b) +void BZ_API(BZ2_bzclose) (BZFILE* b) { int bzerr; FILE *fp = ((bzFile *)b)->handle; if (b==NULL) {return;} if(((bzFile*)b)->writing){ - bzWriteClose(&bzerr,b,0,NULL,NULL); + BZ2_bzWriteClose(&bzerr,b,0,NULL,NULL); if(bzerr != BZ_OK){ - bzWriteClose(NULL,b,1,NULL,NULL); + BZ2_bzWriteClose(NULL,b,1,NULL,NULL); } }else{ - bzReadClose(&bzerr,b); + BZ2_bzReadClose(&bzerr,b); } if(fp!=stdin && fp!=stdout){ fclose(fp); @@ -1483,6 +1538,7 @@ static char *bzerrorstrings[] = { ,"IO_ERROR" ,"UNEXPECTED_EOF" ,"OUTBUFF_FULL" + ,"CONFIG_ERROR" ,"???" /* for future */ ,"???" /* for future */ ,"???" /* for future */ @@ -1492,7 +1548,7 @@ static char *bzerrorstrings[] = { }; -const char * BZ_API(bzerror) (BZFILE *b, int *errnum) +const char * BZ_API(BZ2_bzerror) (BZFILE *b, int *errnum) { int err = ((bzFile *)b)->lastErr; -- cgit v1.2.3-55-g6feb