63 #include <grass/config.h> 69 #include <grass/gis.h> 70 #include <grass/glocale.h> 83 G_fatal_error(_(
"GRASS needs to be compiled with BZIP2 for BZIP2 compression"));
98 if (src_sz <= 0 || dst_sz <= 0) {
100 G_warning(_(
"Invalid source buffer size %d"), src_sz);
102 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
107 buf_sz = (
unsigned int)((
double)dst_sz * 1.01 + (double)600);
109 if (
NULL == (buf = (
unsigned char *)
110 G_calloc(buf_sz,
sizeof(
unsigned char))))
115 err = BZ2_bzBuffToBuffCompress((
char *)buf, &nbytes,
122 G_warning(_(
"BZIP2 version %s compression error %d"),
123 BZ2_bzlibVersion(), err);
129 if (nbytes >= (
unsigned int)src_sz) {
136 if ((
unsigned int)dst_sz < nbytes)
140 for (i = 0; i < nbytes; i++)
157 G_fatal_error(_(
"GRASS needs to be compiled with BZIP2 for BZIP2 compression"));
172 if (src_sz <= 0 || dst_sz <= 0) {
174 G_warning(_(
"Invalid source buffer size %d"), src_sz);
176 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
183 err = BZ2_bzBuffToBuffDecompress((
char *)dst, &nbytes,
189 G_warning(_(
"BZIP2 version %s decompression error %d"),
190 BZ2_bzlibVersion(), err);
198 if (nbytes != dst_sz) {
200 G_warning(_(
"Got uncompressed size %d, expected %d"), (
int)nbytes, dst_sz);
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
int G_bz2_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
void G_free(void *buf)
Free allocated memory.
void G_warning(const char *msg,...)
Print a warning message to stderr.
int G_bz2_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)