解压uimage.gz的函数
时间: 2023-09-25 18:12:33 浏览: 146
以下是解压uimage.gz的函数示例:
```c
#include <zlib.h>
int uncompress_image(unsigned char *src, unsigned char *dst, int src_len, int dst_len) {
int ret;
z_stream strm;
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = src_len;
strm.next_in = src;
strm.avail_out = dst_len;
strm.next_out = dst;
ret = inflateInit2(&strm, 16 + MAX_WBITS);
if (ret != Z_OK) {
return ret;
}
ret = inflate(&strm, Z_FINISH);
if (ret != Z_STREAM_END) {
inflateEnd(&strm);
return ret == Z_OK ? Z_BUF_ERROR : ret;
}
ret = inflateEnd(&strm);
if (ret != Z_OK) {
return ret;
}
return dst_len - strm.avail_out;
}
```
该函数使用 zlib 库中的 inflate 函数进行解压缩。将源数据和目标缓冲区作为参数传递给函数,并且返回解压后的数据长度。
阅读全文