#[unsafe(export_name = "zError")]pub const extern "C" fn zError(err: i32) -> *const i8Expand description
Get the error message for an error. This could be the value returned by e.g. compress or
inflate.
The return value is a pointer to a NULL-terminated sequence of bytes
ยงExample
use libz_rs_sys::*;
use core::ffi::{c_char, CStr};
fn cstr<'a>(ptr: *const c_char) -> &'a [u8] {
// SAFETY: we trust the input
unsafe { CStr::from_ptr(ptr) }.to_bytes()
}
// defined error values give a short message
assert_eq!(cstr(zError(Z_NEED_DICT)), b"need dictionary");
assert_eq!(cstr(zError(Z_NEED_DICT)), b"need dictionary");
assert_eq!(cstr(zError(Z_STREAM_END)), b"stream end");
assert_eq!(cstr(zError(Z_OK)), b"");
assert_eq!(cstr(zError(Z_ERRNO)), b"file error");
assert_eq!(cstr(zError(Z_STREAM_ERROR)), b"stream error");
assert_eq!(cstr(zError(Z_DATA_ERROR)), b"data error");
assert_eq!(cstr(zError(Z_MEM_ERROR)), b"insufficient memory");
assert_eq!(cstr(zError(Z_BUF_ERROR)), b"buffer error");
assert_eq!(cstr(zError(Z_VERSION_ERROR)), b"incompatible version");
// other inputs return an empty string
assert_eq!(cstr(zError(1234)), b"");