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"));
172 memcpy(dst, src, src_sz);
194 memcpy(dst, src, src_sz);
207 if (number < 0 || number >= n_compressors) {
224 if (number < 0 || number >= n_compressors) {
239 if (number < 0 || number >= n_compressors) {
250 int bsize, nread,
err;
253 if (dst ==
NULL || nbytes <= 0) {
255 G_warning(
_(
"No destination buffer allocated"));
257 G_warning(
_(
"Invalid destination buffer size %d"), nbytes);
269 if (
NULL == (b = (
unsigned char *)
270 G_calloc(bsize,
sizeof(
unsigned char))))
276 err = read(fd, b + nread, bsize - nread);
279 }
while (err > 0 && nread < bsize);
283 G_warning(
_(
"Unable to read %d bytes: end of file"), rbytes);
285 G_warning(
_(
"Unable to read %d bytes: %s"), rbytes, strerror(errno));
290 if (nread < rbytes) {
292 G_warning(
"Unable to read %d bytes, got %d bytes", rbytes, nread);
299 for (err = 0; err < nread - 1 && err < nbytes; err++)
300 dst[err] = b[err + 1];
308 G_warning(
"Read error: We're not at the start of a row");
316 err =
G_expand(b + 1, bsize - 1, dst, nbytes, number);
329 int dst_sz, nwritten,
err;
330 unsigned char *
dst, compressed;
333 if (src ==
NULL || nbytes < 0) {
337 G_warning(
_(
"Invalid source buffer size %d"), nbytes);
343 if (
NULL == (dst = (
unsigned char *)
344 G_calloc(dst_sz,
sizeof(
unsigned char))))
348 err =
G_compress(src, nbytes, dst, dst_sz, number);
354 if (err > 0 && err < nbytes) {
358 if (write(fd, &compressed, 1) != 1) {
360 G_warning(
_(
"Unable to write compression flag"));
365 err = write(fd, dst + nwritten, dst_sz - nwritten);
368 }
while (err > 0 && nwritten < dst_sz);
371 G_warning(
_(
"Unable to write %d bytes: nothing written"), dst_sz);
373 G_warning(
_(
"Unable to write %d bytes: %s"), dst_sz, strerror(errno));
381 if (write(fd, &compressed, 1) != 1) {
383 G_warning(
_(
"Unable to write compression flag"));
388 err = write(fd, src + nwritten, nbytes - nwritten);
391 }
while (err > 0 && nwritten < nbytes);
394 G_warning(
_(
"Unable to write %d bytes: nothing written"), nbytes);
396 G_warning(
_(
"Unable to write %d bytes: %s"), nbytes, strerror(errno));
415 unsigned char compressed;
418 if (src ==
NULL || nbytes < 0)
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, strerror(errno));
442 if (err < 0 || nwritten != nbytes)
int G_default_compressor(void)
int G_read_compressed(int fd, int rbytes, unsigned char *dst, int nbytes, int number)
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
struct compressor_list compressor[]
int G_no_compress_bound(int src_sz)
int G_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz, int number)
char * G_compressor_name(int number)
void G_free(void *)
Free allocated memory.
int G_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz, int number)
SYMBOL * err(FILE *fp, SYMBOL *s, char *msg)
int G_no_expand(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_write_uncompressed(int fd, const unsigned char *src, int nbytes)
int int G_strcasecmp(const char *, const char *)
String compare ignoring case (upper or lower)
int G_no_compress(unsigned char *src, int src_sz, unsigned char *dst, int dst_sz)
int G_compress_bound(int src_sz, int number)
int G_check_compressor(int number)
int G_compressor_number(char *name)
int G_write_compressed(int fd, unsigned char *src, int nbytes, int number)
void G_warning(const char *,...) __attribute__((format(printf