Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
gunzip.cpp@3:ed54c8225fe6, 2017-02-28 (annotated)
- Committer:
- ansond
- Date:
- Tue Feb 28 16:50:16 2017 +0000
- Revision:
- 3:ed54c8225fe6
- Parent:
- gunzip.c@1:2a3edb8df037
updated
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ansond | 1:2a3edb8df037 | 1 | #include "mbed.h" |
| ansond | 1:2a3edb8df037 | 2 | #include "zlib.h" |
| ansond | 1:2a3edb8df037 | 3 | |
| ansond | 1:2a3edb8df037 | 4 | /** GUNZIP a from src buffer to dst buffer |
| ansond | 1:2a3edb8df037 | 5 | @param dst : destination buffer |
| ansond | 1:2a3edb8df037 | 6 | @param dst_length : pointer to destination buffer length |
| ansond | 1:2a3edb8df037 | 7 | @param src : source buffer |
| ansond | 1:2a3edb8df037 | 8 | @param src_length : source buffer length |
| ansond | 1:2a3edb8df037 | 9 | @return Z_OK on success, zlib error (<0) on failure |
| ansond | 1:2a3edb8df037 | 10 | */ |
| ansond | 3:ed54c8225fe6 | 11 | extern "C" int gunzip(unsigned char *dst, unsigned long *dst_length, unsigned char *src, unsigned long src_length) |
| ansond | 1:2a3edb8df037 | 12 | { |
| ansond | 1:2a3edb8df037 | 13 | z_stream stream; |
| ansond | 1:2a3edb8df037 | 14 | memset(&stream, 0, sizeof(stream)); |
| ansond | 1:2a3edb8df037 | 15 | |
| ansond | 1:2a3edb8df037 | 16 | stream.next_in = src; |
| ansond | 1:2a3edb8df037 | 17 | stream.avail_in = src_length; |
| ansond | 1:2a3edb8df037 | 18 | |
| ansond | 1:2a3edb8df037 | 19 | stream.next_out = dst; |
| ansond | 1:2a3edb8df037 | 20 | stream.avail_out = *dst_length; |
| ansond | 1:2a3edb8df037 | 21 | |
| ansond | 1:2a3edb8df037 | 22 | int rv = inflateInit2(&stream, 15 + 16); |
| ansond | 1:2a3edb8df037 | 23 | if (Z_OK == rv) { |
| ansond | 1:2a3edb8df037 | 24 | rv = inflate(&stream, Z_NO_FLUSH); |
| ansond | 1:2a3edb8df037 | 25 | if (Z_STREAM_END == rv) { |
| ansond | 1:2a3edb8df037 | 26 | inflateEnd(&stream); |
| ansond | 1:2a3edb8df037 | 27 | rv = Z_OK; |
| ansond | 1:2a3edb8df037 | 28 | } |
| ansond | 1:2a3edb8df037 | 29 | } |
| ansond | 1:2a3edb8df037 | 30 | |
| ansond | 1:2a3edb8df037 | 31 | if (Z_OK == rv) { |
| ansond | 1:2a3edb8df037 | 32 | *dst_length = stream.total_out; |
| ansond | 1:2a3edb8df037 | 33 | } else { |
| ansond | 1:2a3edb8df037 | 34 | *dst_length = 0; |
| ansond | 1:2a3edb8df037 | 35 | } |
| ansond | 1:2a3edb8df037 | 36 | |
| ansond | 1:2a3edb8df037 | 37 | return rv; |
| ansond | 1:2a3edb8df037 | 38 | } |