#![allow(non_snake_case)] use crate::errors::{ERR_getErrorCode, ERR_getErrorName, ERR_isError, ZstdErrorCode}; use std::os::raw::{c_char, c_uint}; pub const ZSTD_VERSION_MAJOR: u32 = 1; pub const ZSTD_VERSION_MINOR: u32 = 5; pub const ZSTD_VERSION_RELEASE: u32 = 7; pub const ZSTD_VERSION_NUMBER: u32 = ZSTD_VERSION_MAJOR * 100 * 100 + ZSTD_VERSION_MINOR * 100 + ZSTD_VERSION_RELEASE; #[no_mangle] pub extern "C" fn ZSTD_versionNumber() -> c_uint { ZSTD_VERSION_NUMBER } #[no_mangle] pub extern "C" fn ZSTD_versionString() -> *const c_char { c"1.5.7".as_ptr() } #[no_mangle] pub extern "C" fn ZSTD_isError(code: usize) -> c_uint { ERR_isError(code) as c_uint } #[no_mangle] pub extern "C" fn ZSTD_getErrorName(code: usize) -> *const c_char { ERR_getErrorName(code) } #[no_mangle] pub extern "C" fn ZSTD_getErrorCode(code: usize) -> i32 { ERR_getErrorCode(code) } // ZSTD_getErrorString lives in errors.rs (also used as ERR_getErrorString). /// Convenience re-export of the error enum for callers of the common module. pub type ErrorCode = ZstdErrorCode; #[cfg(test)] mod tests { use super::*; use crate::errors::{ZstdErrorCode, ERROR}; use std::ffi::CStr; #[test] fn version_exports_match_zstd_h() { assert_eq!(ZSTD_versionNumber(), 10_507); let version = unsafe { CStr::from_ptr(ZSTD_versionString()) }; assert_eq!(version.to_bytes(), b"1.5.7"); } #[test] fn public_error_exports_preserve_numeric_codes() { let error = ERROR(ZstdErrorCode::CorruptionDetected); assert_eq!(ZSTD_isError(error), 1); assert_eq!(ZSTD_getErrorCode(error), 20); assert_eq!(ZSTD_getErrorCode(usize::MAX - 1), 2); let name = unsafe { CStr::from_ptr(ZSTD_getErrorName(error)) }; assert_eq!(name.to_bytes(), b"Data corruption detected"); } }