Skip to main content

libzstd_rs_sys/lib/common/
zstd_common.rs

1use libc::size_t;
2
3use crate::lib::common::error_private::{
4    ERR_getErrorCode, ERR_getErrorName, ERR_getErrorString, ERR_isError,
5};
6use crate::lib::zstd::{ZSTD_ErrorCode, ZSTD_VERSION_NUMBER};
7
8/// Get the zstd version number
9///
10/// # Returns
11///
12/// - the runtime library version, as `(MAJOR*100*100 + MINOR*100 + RELEASE)`
13#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_versionNumber))]
14pub const extern "C" fn ZSTD_versionNumber() -> core::ffi::c_uint {
15    ZSTD_VERSION_NUMBER as core::ffi::c_uint
16}
17
18/// Get a zstd version string
19///
20/// # Returns
21///
22/// - the runtime library version, like "1.5.8"
23#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_versionString))]
24pub const extern "C" fn ZSTD_versionString() -> *const core::ffi::c_char {
25    c"1.5.8".as_ptr()
26}
27
28/// Most functions returning a `size_t` value can be tested for errors, using [`ZSTD_isError`].
29///
30/// # Returns
31///
32/// - 1 if the provided code is an error
33/// - 0 otherwise
34#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_isError))]
35pub const extern "C" fn ZSTD_isError(code: size_t) -> core::ffi::c_uint {
36    ERR_isError(code) as _
37}
38
39/// Provides a readable error string from a function result
40#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_getErrorName))]
41pub extern "C" fn ZSTD_getErrorName(code: size_t) -> *const core::ffi::c_char {
42    ERR_getErrorName(code)
43}
44
45/// Convert a result into an error code, which can be compared to the errors enum list
46#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_getErrorCode))]
47pub extern "C" fn ZSTD_getErrorCode(code: size_t) -> ZSTD_ErrorCode {
48    ERR_getErrorCode(code)
49}
50
51/// Provides a readable error string from an error code
52///
53/// Unlike [`ZSTD_getErrorName`], this method should not be used on `size_t` function results
54#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_getErrorString))]
55pub extern "C" fn ZSTD_getErrorString(code: ZSTD_ErrorCode) -> *const core::ffi::c_char {
56    ERR_getErrorString(code)
57}
58
59/// This is mainly used for Zstd's determinism test suite, which is only run when this function
60/// returns 1.
61///
62/// # Returns
63///
64/// - 1 if the library is built using standard compilation flags and participates in determinism
65///   guarantees with other builds of the same version.
66/// - 0 if the library was compiled with non-standard compilation flags that change the output of
67///   the compressor.
68#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_isDeterministicBuild))]
69pub extern "C" fn ZSTD_isDeterministicBuild() -> core::ffi::c_int {
70    true as core::ffi::c_int
71}