62#include <grass/config.h>
66#error "GRASS requires libz to compile"
72#include <grass/glocale.h>
84 return compressBound(src_sz);
87int G_zlib_compress(
unsigned char *src,
int src_sz,
unsigned char *dst,
90 uLong
err, nbytes, buf_sz;
104 if (src_sz <= 0 || dst_sz <= 0) {
106 G_warning(_(
"Invalid source buffer size %d"), src_sz);
108 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
118 if (dst_sz < 0 || buf_sz > (
unsigned int)dst_sz) {
120 "G_zlib_compress(): programmer error, destination is too small");
122 (buf = (
unsigned char *)G_calloc(buf_sz,
sizeof(
unsigned char))))
135 err = compress2((Bytef *)buf, &nbytes,
136 (
const Bytef *)src, src_sz,
147 if (src_sz < 0 || nbytes >= (
unsigned int)src_sz) {
165int G_zlib_expand(
unsigned char *src,
int src_sz,
unsigned char *dst,
182 if (src_sz <= 0 || dst_sz <= 0) {
184 G_warning(_(
"Invalid source buffer size %d"), src_sz);
186 G_warning(_(
"Invalid destination buffer size %d"), dst_sz);
194 err = uncompress((Bytef *)dst, &nbytes,
195 (
const Bytef *)src, ss);
207 if (dst_sz < 0 || nbytes != (
unsigned int)dst_sz) {
209 G_warning(_(
"Got uncompressed size %d, expected %d"), (
int)nbytes,
void G_free(void *buf)
Free allocated memory.
int G_zlib_compress_bound(int)
void G_warning(const char *msg,...)
Print a warning message to stderr.
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)