本文整理汇总了C++中zlib_inflate函数的典型用法代码示例。如果您正苦于以下问题:C++ zlib_inflate函数的具体用法?C++ zlib_inflate怎么用?C++ zlib_inflate使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了zlib_inflate函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cramfs_uncompress_block_gzip
/* Returns length of decompressed data. */
int cramfs_uncompress_block_gzip(void *dst, int dstlen, void *src, int srclen)
{
int err;
stream.next_in = src;
stream.avail_in = srclen;
stream.next_out = dst;
stream.avail_out = dstlen;
err = zlib_inflateReset(&stream);
if (err != Z_OK) {
printk("zlib_inflateReset error %d\n", err);
zlib_inflateEnd(&stream);
zlib_inflateInit(&stream);
}
err = zlib_inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
goto err;
return stream.total_out;
err:
printk("Error %d while decompressing!\n", err);
printk("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
return 0;
}
示例2: pstore_decompress
/* Derived from logfs_uncompress */
static int pstore_decompress(void *in, void *out, size_t inlen, size_t outlen)
{
int err, ret;
ret = -EIO;
err = zlib_inflateInit2(&stream, WINDOW_BITS);
if (err != Z_OK)
goto error;
stream.next_in = in;
stream.avail_in = inlen;
stream.total_in = 0;
stream.next_out = out;
stream.avail_out = outlen;
stream.total_out = 0;
err = zlib_inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
goto error;
err = zlib_inflateEnd(&stream);
if (err != Z_OK)
goto error;
ret = stream.total_out;
error:
return ret;
}
示例3: gztruncate
// There is no zlib gztruncate. Inflate it, truncate it, recompress it.
static int gztruncate(const char *path, off_t length, int compression)
{
int ret=1;
char tmp[16];
char *dest=NULL;
char *dest2=NULL;
snprintf(tmp, sizeof(tmp), ".%d", getpid());
if(!(dest=prepend(path, tmp))
|| !(dest2=prepend(dest, "-2"))
|| zlib_inflate(NULL, path, dest, NULL))
goto end;
if(truncate(dest, length))
{
logp("truncate of %s failed in %s\n", dest, __func__);
goto end;
}
if(compress_file(dest, dest2, compression))
goto end;
unlink(dest);
ret=do_rename(dest2, path);
end:
if(dest) unlink(dest);
if(dest2) unlink(dest2);
free_w(&dest);
free_w(&dest2);
return ret;
}
示例4: ctf_uncompress
int ctf_uncompress (char *dest, int *destLen, char *source, int sourceLen)
{
z_stream stream;
int err;
memset(&stream, 0, sizeof stream);
stream.next_in = source;
stream.avail_in = sourceLen;
/* Check for source > 64K on 16-bit machine: */
if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
stream.next_out = dest;
stream.avail_out = (uInt)*destLen;
if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
err = zlib_inflateInit(&stream);
if (err != Z_OK) return err;
err = zlib_inflate(&stream, Z_FINISH);
last_err = stream.msg;
if (err != Z_STREAM_END) {
zlib_inflateEnd(&stream);
if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
return Z_DATA_ERROR;
return err;
}
*destLen = stream.total_out;
err = zlib_inflateEnd(&stream);
return err;
}
示例5: logfs_uncompress
int logfs_uncompress(void *in, void *out, size_t inlen, size_t outlen)
{
int err, ret;
ret = -EIO;
mutex_lock(&compr_mutex);
err = zlib_inflateInit(&stream);
if (err != Z_OK)
goto error;
stream.next_in = in;
stream.avail_in = inlen;
stream.total_in = 0;
stream.next_out = out;
stream.avail_out = outlen;
stream.total_out = 0;
err = zlib_inflate(&stream, Z_FINISH);
if (err != Z_STREAM_END)
goto error;
err = zlib_inflateEnd(&stream);
if (err != Z_OK)
goto error;
ret = 0;
error:
mutex_unlock(&compr_mutex);
return ret;
}
示例6: zlib_decompress_final
static int zlib_decompress_final(struct crypto_pcomp *tfm,
struct comp_request *req)
{
int ret;
struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
struct z_stream_s *stream = &dctx->decomp_stream;
pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
stream->next_in = req->next_in;
stream->avail_in = req->avail_in;
stream->next_out = req->next_out;
stream->avail_out = req->avail_out;
if (dctx->decomp_windowBits < 0) {
ret = zlib_inflate(stream, Z_SYNC_FLUSH);
/*
* Work around a bug in zlib, which sometimes wants to taste an
* extra byte when being used in the (undocumented) raw deflate
* mode. (From USAGI).
*/
if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
const void *saved_next_in = stream->next_in;
u8 zerostuff = 0;
stream->next_in = &zerostuff;
stream->avail_in = 1;
ret = zlib_inflate(stream, Z_FINISH);
stream->next_in = saved_next_in;
stream->avail_in = 0;
}
} else
ret = zlib_inflate(stream, Z_FINISH);
if (ret != Z_STREAM_END) {
pr_debug("zlib_inflate failed %d\n", ret);
return -EINVAL;
}
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, ret);
req->next_in = stream->next_in;
req->avail_in = stream->avail_in;
req->next_out = stream->next_out;
req->avail_out = stream->avail_out;
return ret;
}
示例7: geDecompress
ge_Buffer* geDecompress(void* in, int insz, int mode){
ge_Buffer* out = (ge_Buffer*)geMalloc(sizeof(ge_Buffer));
if(mode == GE_COMPRESSION_ZLIB){
ge_Buffer b_in = { in, insz, 0 };
zlib_inflate(out, &b_in);
}
return out;
}
示例8: inflate_or_link_oldfile
static int inflate_or_link_oldfile(const char *oldpath, const char *infpath)
{
int ret=0;
struct stat statp;
if(lstat(oldpath, &statp))
{
logp("could not lstat %s\n", oldpath);
return -1;
}
if(dpth_is_compressed(oldpath))
{
FILE *source=NULL;
FILE *dest=NULL;
//logp("inflating...\n");
if(!(dest=open_file(infpath, "wb")))
{
close_fp(&dest);
return -1;
}
if(!statp.st_size)
{
// Empty file - cannot inflate.
// just close the destination and we have duplicated a
// zero length file.
logp("asked to inflate zero length file: %s\n", oldpath);
close_fp(&dest);
return 0;
}
if(!(source=open_file(oldpath, "rb")))
{
close_fp(&dest);
return -1;
}
if((ret=zlib_inflate(source, dest))!=Z_OK)
logp("zlib_inflate returned: %d\n", ret);
close_fp(&source);
close_fp(&dest);
}
else
{
// Not compressed - just hard link it.
if(link(oldpath, infpath))
{
logp("hardlink %s to %s failed: %s\n",
infpath, oldpath, strerror(errno));
ret=-1;
}
}
return ret;
}
示例9: zlib_decompress_final
static int zlib_decompress_final(struct crypto_pcomp *tfm,
struct comp_request *req)
{
int ret;
struct zlib_ctx *dctx = crypto_tfm_ctx(crypto_pcomp_tfm(tfm));
struct z_stream_s *stream = &dctx->decomp_stream;
pr_debug("avail_in %u, avail_out %u\n", req->avail_in, req->avail_out);
stream->next_in = req->next_in;
stream->avail_in = req->avail_in;
stream->next_out = req->next_out;
stream->avail_out = req->avail_out;
if (dctx->decomp_windowBits < 0) {
ret = zlib_inflate(stream, Z_SYNC_FLUSH);
if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
const void *saved_next_in = stream->next_in;
u8 zerostuff = 0;
stream->next_in = &zerostuff;
stream->avail_in = 1;
ret = zlib_inflate(stream, Z_FINISH);
stream->next_in = saved_next_in;
stream->avail_in = 0;
}
} else
ret = zlib_inflate(stream, Z_FINISH);
if (ret != Z_STREAM_END) {
pr_debug("zlib_inflate failed %d\n", ret);
return -EINVAL;
}
ret = req->avail_out - stream->avail_out;
pr_debug("avail_in %u, avail_out %u (consumed %u, produced %u)\n",
stream->avail_in, stream->avail_out,
req->avail_in - stream->avail_in, ret);
req->next_in = stream->next_in;
req->avail_in = stream->avail_in;
req->next_out = stream->next_out;
req->avail_out = stream->avail_out;
return ret;
}
示例10: sqlzma_un
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
struct sized_buf *dst)
{
int err, by_lzma = 1;
if (un->un_lzma && is_lzma(*src->buf)) {
un->un_cmbuf = src->buf;
un->un_cmlen = src->sz;
un->un_resbuf = dst->buf;
un->un_reslen = dst->sz;
/* this library is thread-safe */
err = LzmaUncompress(un);
goto out;
}
by_lzma = 0;
//#if defined(CONFIG_MIPS_BRCM)
#if 1//disable zlib inflate
/* The FS is compressed with LZMA for BRCM: do not use zlib */
printk("%s: ZLIB decompression is not supported\n", __func__);
err = -EINVAL;
#else
err = zlib_inflateReset(&un->un_stream);
if (unlikely(err != Z_OK))
goto out;
un->un_stream.next_in = src->buf;
un->un_stream.avail_in = src->sz;
un->un_stream.next_out = dst->buf;
un->un_stream.avail_out = dst->sz;
err = zlib_inflate(&un->un_stream, Z_FINISH);
if (err == Z_STREAM_END)
err = 0;
#endif
out:
if (unlikely(err)) {
#ifdef __KERNEL__
WARN_ON_ONCE(1);
#else
char a[64] = "ZLIB ";
if (by_lzma) {
strcpy(a, "LZMA ");
#ifdef _REENTRANT
strerror_r(err, a + 5, sizeof(a) - 5);
#else
strncat(a, strerror(err), sizeof(a) - 5);
#endif
} else
strncat(a, zError(err), sizeof(a) - 5);
fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
#endif
}
return err;
}
示例11: deflate_decompress
static int deflate_decompress(struct crypto_tfm *tfm, const u8 *src,
unsigned int slen, u8 *dst, unsigned int *dlen)
{
int ret = 0;
struct deflate_ctx *dctx = crypto_tfm_ctx(tfm);
struct z_stream_s *stream = &dctx->decomp_stream;
ret = zlib_inflateReset(stream);
if (ret != Z_OK) {
ret = -EINVAL;
goto out;
}
stream->next_in = (u8 *)src;
stream->avail_in = slen;
stream->next_out = (u8 *)dst;
stream->avail_out = *dlen;
ret = zlib_inflate(stream, Z_SYNC_FLUSH);
/*
* Work around a bug in zlib, which sometimes wants to taste an extra
* byte when being used in the (undocumented) raw deflate mode.
* (From USAGI).
*/
if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
u8 zerostuff = 0;
stream->next_in = &zerostuff;
stream->avail_in = 1;
ret = zlib_inflate(stream, Z_FINISH);
}
if (ret != Z_STREAM_END) {
ret = -EINVAL;
goto out;
}
ret = 0;
*dlen = stream->total_out;
out:
return ret;
}
示例12: gunzip
static void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
{
z_stream s;
int r, i, flags;
/* skip header */
i = 10;
flags = src[3];
if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
printf("bad gzipped data\n\r");
exit();
}
if ((flags & EXTRA_FIELD) != 0)
i = 12 + src[10] + (src[11] << 8);
if ((flags & ORIG_NAME) != 0)
while (src[i++] != 0)
;
if ((flags & COMMENT) != 0)
while (src[i++] != 0)
;
if ((flags & HEAD_CRC) != 0)
i += 2;
if (i >= *lenp) {
printf("gunzip: ran out of data in header\n\r");
exit();
}
if (zlib_inflate_workspacesize() > sizeof(scratch)) {
printf("gunzip needs more mem\n");
exit();
}
memset(&s, 0, sizeof(s));
s.workspace = scratch;
r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) {
printf("inflateInit2 returned %d\n\r", r);
exit();
}
s.next_in = src + i;
s.avail_in = *lenp - i;
s.next_out = dst;
s.avail_out = dstlen;
r = zlib_inflate(&s, Z_FULL_FLUSH);
if (r != Z_OK && r != Z_STREAM_END) {
printf("inflate returned %d msg: %s\n\r", r, s.msg);
exit();
}
*lenp = s.next_out - (unsigned char *) dst;
zlib_inflateEnd(&s);
}
示例13: sqlzma_un
int sqlzma_un(struct sqlzma_un *un, struct sized_buf *src,
struct sized_buf *dst)
{
int err, by_lzma = 0;
if (un->un_lzma && is_lzma(*src->buf)) {
by_lzma = 1;
un->un_cmbuf = src->buf;
un->un_cmlen = src->sz;
un->un_resbuf = dst->buf;
un->un_reslen = dst->sz;
/* this library is thread-safe */
err = LzmaUncompress(un);
goto out;
}
err = zlib_inflateReset(&un->un_stream);
if (unlikely(err != Z_OK))
goto out;
un->un_stream.next_in = src->buf;
un->un_stream.avail_in = src->sz;
un->un_stream.next_out = dst->buf;
un->un_stream.avail_out = dst->sz;
err = zlib_inflate(&un->un_stream, Z_FINISH);
if (err == Z_STREAM_END)
err = 0;
out:
if (err) {
#ifdef __KERNEL__
WARN_ON_ONCE(1);
#else
char a[64] = "ZLIB ";
if (by_lzma) {
strcpy(a, "LZMA ");
#ifdef _REENTRANT
strerror_r(err, a + 5, sizeof(a) - 5);
#else
strncat(a, strerror(err), sizeof(a) - 5);
#endif
} else
strncat(a, zError(err), sizeof(a) - 5);
fprintf(stderr, "%s: %.*s\n", __func__, sizeof(a), a);
#endif
}
return err;
}
示例14: gunzip
void gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
{
z_stream s;
int r, i, flags;
/* skip header */
i = 10;
flags = src[3];
if (src[2] != Z_DEFLATED || (flags & RESERVED) != 0) {
puts("bad gzipped data\n");
exit();
}
if ((flags & EXTRA_FIELD) != 0)
i = 12 + src[10] + (src[11] << 8);
if ((flags & ORIG_NAME) != 0)
while (src[i++] != 0)
;
if ((flags & COMMENT) != 0)
while (src[i++] != 0)
;
if ((flags & HEAD_CRC) != 0)
i += 2;
if (i >= *lenp) {
puts("gunzip: ran out of data in header\n");
exit();
}
/* Initialize ourself. */
s.workspace = zalloc(zlib_inflate_workspacesize());
r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) {
puts("zlib_inflateInit2 returned "); puthex(r); puts("\n");
exit();
}
s.next_in = src + i;
s.avail_in = *lenp - i;
s.next_out = dst;
s.avail_out = dstlen;
r = zlib_inflate(&s, Z_FINISH);
if (r != Z_OK && r != Z_STREAM_END) {
puts("inflate returned "); puthex(r); puts("\n");
exit();
}
*lenp = s.next_out - (unsigned char *) dst;
zlib_inflateEnd(&s);
}
示例15: gunzip
void gunzip (void *dst, int dstlen, unsigned char *src, int *lenp)
{
z_stream s;
int r, i, flags;
i = 10;
flags = src[3];
if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
exit();
}
if ((flags & EXTRA_FIELD) != 0)
i = 12 + src[10] + (src[11] << 8);
if ((flags & ORIG_NAME) != 0)
while (src[i++] != 0)
;
if ((flags & COMMENT) != 0)
while (src[i++] != 0)
;
if ((flags & HEAD_CRC) != 0)
i += 2;
if (i >= *lenp) {
exit();
}
s.workspace = zalloc(zlib_inflate_workspacesize());
r = zlib_inflateInit2(&s, -MAX_WBITS);
if (r != Z_OK) {
exit();
}
s.next_in = src + i;
s.avail_in = *lenp - i;
s.next_out = dst;
s.avail_out = dstlen;
r = zlib_inflate(&s, Z_FINISH);
if (r != Z_OK && r != Z_STREAM_END) {
exit();
}
*lenp = s.next_out - (unsigned char *) dst;
zlib_inflateEnd(&s);
}