Add zlib error code to string conversion

This commit is contained in:
Danny Robson 2013-07-30 01:41:54 +10:00
parent 6e71e8674d
commit db2fa04765
2 changed files with 26 additions and 0 deletions

View File

@ -8,6 +8,31 @@ util::zlib::version (void) {
}
const char*
util::zlib::code_to_string (int code) {
static const int MIN_CODE = -6;
static const int MAX_CODE = 2;
if (code > MAX_CODE || code < MIN_CODE) {
unreachable ();
}
static const char* CODES[] = {
"OK",
"STREAM_END",
"NEED_DICT",
"ERRNO",
"STREAM_ERROR",
"DATA_ERROR",
"MEM_ERROR",
"BUF_ERROR",
"VERSION_ERROR",
};
return CODES[code + MIN_CODE];
}
size_t
util::zlib::uncompress (uint8_t *dst, size_t dst_len,
const uint8_t *src, size_t src_len) {

View File

@ -29,6 +29,7 @@
namespace util {
namespace zlib {
extern const char* version (void);
extern const char* code_to_string (int);
extern void compress (uint8_t *dst, size_t dst_len,
const uint8_t *src, size_t src_len,