63#include <grass/config.h>
70#include <grass/glocale.h>
90 unsigned int i, nbytes;
95 _(
"GRASS needs to be compiled with BZIP2 for BZIP2 compression"));
110 if (src_sz <= 0 || dst_sz <= 0) {
112 G_warning(_(
"Invalid source buffer size %d"), src_sz);
114 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
122 if (buf_sz > dst_sz) {
124 "G_bz2_compress(): programmer error, destination is too small");
126 (buf = (
unsigned char *)G_calloc(buf_sz,
sizeof(
unsigned char))))
134 err = BZ2_bzBuffToBuffCompress((
char *)buf, &nbytes,
141 G_warning(_(
"BZIP2 version %s compression error %d"),
142 BZ2_bzlibVersion(),
err);
149 if (nbytes >= (
unsigned int)src_sz) {
158 for (i = 0; i < nbytes; i++)
168int G_bz2_expand(
unsigned char *src,
int src_sz,
unsigned char *dst,
int dst_sz)
175 _(
"GRASS needs to be compiled with BZIP2 for BZIP2 compression"));
190 if (src_sz <= 0 || dst_sz <= 0) {
192 G_warning(_(
"Invalid source buffer size %d"), src_sz);
194 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
200 err = BZ2_bzBuffToBuffDecompress((
char *)dst, &nbytes,
206 G_warning(_(
"BZIP2 version %s decompression error %d"),
207 BZ2_bzlibVersion(),
err);
215 if (dst_sz < 0 || nbytes != (
unsigned int)dst_sz) {
217 G_warning(_(
"Got uncompressed size %d, expected %d"), (
int)nbytes,
void G_free(void *buf)
Free allocated memory.
int G_bz2_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_bz2_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_bz2_compress_bound(int src_sz)
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void G_warning(const char *msg,...)
Print a warning message to stderr.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)