94 #define G_COMPRESSED_NO (unsigned char)'0'
95 #define G_COMPRESSED_YES (unsigned char)'1'
120 if (number < 0 || number >= n_compressors)
142 if (number < 0 || number >= n_compressors) {
143 G_warning(
_(
"Request for unsupported compressor"));
204 if (number < 0 || number >= n_compressors) {
221 if (number < 0 || number >= n_compressors) {
236 if (number < 0 || number >= n_compressors) {
247 int bsize, nread,
err;
250 if (
dst ==
NULL || nbytes <= 0) {
252 G_warning(
_(
"No destination buffer allocated"));
254 G_warning(
_(
"Invalid destination buffer size %d"), nbytes);
266 if (
NULL == (
b = (
unsigned char *)
G_calloc(bsize,
sizeof(
unsigned char))))
272 err = read(fd,
b + nread, bsize - nread);
275 }
while (
err > 0 && nread < bsize);
279 G_warning(
_(
"Unable to read %d bytes: end of file"), rbytes);
281 G_warning(
_(
"Unable to read %d bytes: %s"), rbytes,
287 if (nread < rbytes) {
289 G_warning(
"Unable to read %d bytes, got %d bytes", rbytes, nread);
305 G_warning(
"Read error: We're not at the start of a row");
325 int dst_sz, nwritten,
err;
326 unsigned char *
dst, compressed;
329 if (
src ==
NULL || nbytes < 0) {
333 G_warning(
_(
"Invalid source buffer size %d"), nbytes);
340 (
dst = (
unsigned char *)
G_calloc(dst_sz,
sizeof(
unsigned char))))
350 if (
err > 0 &&
err < nbytes) {
354 if (write(fd, &compressed, 1) != 1) {
356 G_warning(
_(
"Unable to write compression flag"));
361 err = write(fd,
dst + nwritten, dst_sz - nwritten);
364 }
while (
err > 0 && nwritten < dst_sz);
367 G_warning(
_(
"Unable to write %d bytes: nothing written"),
370 G_warning(
_(
"Unable to write %d bytes: %s"), dst_sz,
379 if (write(fd, &compressed, 1) != 1) {
381 G_warning(
_(
"Unable to write compression flag"));
386 err = write(fd,
src + nwritten, nbytes - nwritten);
389 }
while (
err > 0 && nwritten < nbytes);
392 G_warning(
_(
"Unable to write %d bytes: nothing written"),
395 G_warning(
_(
"Unable to write %d bytes: %s"), nbytes,
415 unsigned char compressed;
423 if (write(fd, &compressed, 1) != 1) {
424 G_warning(
_(
"Unable to write compression flag"));
431 err = write(fd,
src + nwritten, nbytes - nwritten);
434 }
while (
err > 0 && nwritten < nbytes);
437 G_warning(
_(
"Unable to write %d bytes: nothing written"), nbytes);
439 G_warning(
_(
"Unable to write %d bytes: %s"), nbytes,
443 if (
err < 0 || nwritten != nbytes)
int G_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz, int number)
int G_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz, int number)
int G_write_compressed(int fd, unsigned char *src, int nbytes, int number)
int G_default_compressor(void)
int G_write_uncompressed(int fd, const unsigned char *src, int nbytes)
int G_read_compressed(int fd, int rbytes, unsigned char *dst, int nbytes, int number)
int G_no_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_compressor_number(char *name)
char * G_compressor_name(int number)
int G_check_compressor(int number)
int G_no_compress_bound(int src_sz)
int G_no_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_compress_bound(int src_sz, int number)
struct compressor_list compressor[]
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)