version 1.4, 2005/12/10 20:27:45 |
version 1.5, 2005/12/21 10:49:29 |
|
|
{ |
{ |
CVSZCTX *ctx; |
CVSZCTX *ctx; |
|
|
if ((level < 0) || (level > 9)) { |
if ((level < 0) || (level > 9)) |
cvs_log(LP_ERR, "invalid compression level %d " |
fatal("invalid compression level %d (must be between 0 and 9)", |
"(must be between 0 and 9)", level); |
level); |
return (NULL); |
|
} |
|
|
|
ctx = (CVSZCTX *)xmalloc(sizeof(*ctx)); |
ctx = (CVSZCTX *)xmalloc(sizeof(*ctx)); |
if (ctx == NULL) { |
|
cvs_log(LP_ERRNO, "failed to allocate zlib context"); |
|
return (NULL); |
|
} |
|
memset(ctx, 0, sizeof(*ctx)); |
memset(ctx, 0, sizeof(*ctx)); |
|
|
ctx->z_level = level; |
ctx->z_level = level; |
|
|
ctx->z_destrm.opaque = Z_NULL; |
ctx->z_destrm.opaque = Z_NULL; |
|
|
if ((inflateInit(&(ctx->z_instrm)) != Z_OK) || |
if ((inflateInit(&(ctx->z_instrm)) != Z_OK) || |
(deflateInit(&(ctx->z_destrm), level) != Z_OK)) { |
(deflateInit(&(ctx->z_destrm), level) != Z_OK)) |
cvs_log(LP_ERR, "failed to initialize zlib streams"); |
fatal("failed to initialize zlib streams"); |
xfree(ctx); |
|
return (NULL); |
|
} |
|
|
|
return (ctx); |
return (ctx); |
} |
} |
|
|
|
|
ret = inflate(&(ctx->z_instrm), Z_FINISH); |
ret = inflate(&(ctx->z_instrm), Z_FINISH); |
if ((ret == Z_MEM_ERROR) || (ret == Z_BUF_ERROR) || |
if ((ret == Z_MEM_ERROR) || (ret == Z_BUF_ERROR) || |
(ret == Z_STREAM_ERROR) || (ret == Z_DATA_ERROR)) { |
(ret == Z_STREAM_ERROR) || (ret == Z_DATA_ERROR)) |
cvs_log(LP_ERR, "inflate error: %s", ctx->z_instrm.msg); |
fatal("inflate error: %s", ctx->z_instrm.msg); |
return (-1); |
|
} |
|
|
|
cvs_buf_append(dst, buf, ctx->z_instrm.avail_out); |
cvs_buf_append(dst, buf, ctx->z_instrm.avail_out); |
bytes += sizeof(buf) - ctx->z_instrm.avail_out; |
bytes += sizeof(buf) - ctx->z_instrm.avail_out; |
|
|
ctx->z_destrm.next_out = buf; |
ctx->z_destrm.next_out = buf; |
ctx->z_destrm.avail_out = sizeof(buf); |
ctx->z_destrm.avail_out = sizeof(buf); |
ret = deflate(&(ctx->z_destrm), Z_FINISH); |
ret = deflate(&(ctx->z_destrm), Z_FINISH); |
if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) { |
if ((ret == Z_STREAM_ERROR) || (ret == Z_BUF_ERROR)) |
cvs_log(LP_ERR, "deflate error: %s", ctx->z_destrm.msg); |
fatal("deflate error: %s", ctx->z_destrm.msg); |
return (-1); |
|
} |
|
|
|
if (cvs_buf_append(dst, buf, |
if (cvs_buf_append(dst, buf, |
sizeof(buf) - ctx->z_destrm.avail_out) < 0) |
sizeof(buf) - ctx->z_destrm.avail_out) < 0) |