version 1.1, 2005/01/13 18:59:03 |
version 1.2, 2005/01/13 20:22:55 |
|
|
|
|
#include <sys/param.h> |
#include <sys/param.h> |
|
|
#include <errno.h> |
|
#include <stdio.h> |
|
#include <stdlib.h> |
#include <stdlib.h> |
#include <unistd.h> |
|
#include <string.h> |
#include <string.h> |
|
|
#include "log.h" |
#include "log.h" |
#include "cvs.h" |
#include "cvs.h" |
#include "zlib.h" |
#include "zlib.h" |
|
|
|
|
#define CVS_ZLIB_BUFSIZE 1024 |
#define CVS_ZLIB_BUFSIZE 1024 |
|
|
|
|
|
|
struct cvs_zlib_ctx { |
struct cvs_zlib_ctx { |
int z_level; |
int z_level; |
z_stream z_instrm; |
z_stream z_instrm; |
|
|
/* |
/* |
* cvs_zlib_inflate() |
* cvs_zlib_inflate() |
* |
* |
|
* Decompress the first <slen> bytes of <src> using the zlib context <ctx> and |
|
* store the resulting data in <dst>. |
|
* Returns the number of bytes inflated on success, or -1 on failure. |
*/ |
*/ |
int |
int |
cvs_zlib_inflate(CVSZCTX *ctx, BUF *dst, u_char *src, size_t slen) |
cvs_zlib_inflate(CVSZCTX *ctx, BUF *dst, u_char *src, size_t slen) |
|
|
|
|
} while (ret != Z_STREAM_END); |
} while (ret != Z_STREAM_END); |
|
|
cvs_log(LP_WARN, "%u bytes decompressed to %d bytes", slen, bytes); |
|
|
|
return (bytes); |
return (bytes); |
} |
} |
|
|
|
|
/* |
/* |
* cvs_zlib_deflate() |
* cvs_zlib_deflate() |
* |
* |
|
|
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)) { |
#if 0 |
|
if (ret != Z_OK) { |
|
#endif |
|
cvs_log(LP_ERR, "deflate error: %s", ctx->z_destrm.msg); |
cvs_log(LP_ERR, "deflate error: %s", ctx->z_destrm.msg); |
return (-1); |
return (-1); |
} |
} |
|
|
return (-1); |
return (-1); |
bytes += sizeof(buf) - ctx->z_destrm.avail_out; |
bytes += sizeof(buf) - ctx->z_destrm.avail_out; |
} while (ret != Z_STREAM_END); |
} while (ret != Z_STREAM_END); |
|
|
cvs_log(LP_WARN, "%u bytes compressed to %d bytes", slen, bytes); |
|
|
|
return (bytes); |
return (bytes); |
} |
} |