63 #include <grass/config.h> 67 #error "GRASS requires libz to compile" 72 #include <grass/gis.h> 73 #include <grass/glocale.h> 87 return compressBound(src_sz);
91 G_zlib_compress(
unsigned char *src,
int src_sz,
unsigned char *
dst,
94 uLong
err, nbytes, buf_sz;
108 if (src_sz <= 0 || dst_sz <= 0) {
110 G_warning(_(
"Invalid source buffer size %d"), src_sz);
112 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
122 if (buf_sz > dst_sz) {
123 G_warning(
"G_zlib_compress(): programmer error, destination is too small");
124 if (
NULL == (buf = (
unsigned char *)
125 G_calloc(buf_sz,
sizeof(
unsigned char))))
137 err = compress2((Bytef *)buf, &nbytes,
138 (
const Bytef *)src, src_sz,
142 G_warning(_(
"ZLIB compression error %d: %s"),
143 (
int)err, zError(err));
150 if (nbytes >= src_sz) {
159 for (err = 0; err < nbytes; err++)
170 G_zlib_expand(
unsigned char *src,
int src_sz,
unsigned char *dst,
187 if (src_sz <= 0 || dst_sz <= 0) {
189 G_warning(_(
"Invalid source buffer size %d"), src_sz);
191 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
199 err = uncompress((Bytef *)dst, &nbytes,
200 (
const Bytef *)src, ss);
204 G_warning(_(
"ZLIB decompression error %d: %s"),
213 if (nbytes != dst_sz) {
215 G_warning(_(
"Got uncompressed size %d, expected %d"), (
int)nbytes, dst_sz);
int G_zlib_compress_bound(int)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
void G_free(void *buf)
Free allocated memory.
void G_warning(const char *msg,...)
Print a warning message to stderr.