Files
zstd-rs/rust/cli/src/lib.rs
T
ddidderr 8e241eaa28 refactor(cli): move --list stdin predicate to Rust
The --list stdin callback was a stateless string predicate: it ignored its
opaque context and compared the input name with the fixed stdin marker. Move
that callback under its existing caller symbol into the Rust CLI archive, so
C no longer owns this policy leaf. The Rust implementation preserves the
callback ABI and returns the same 1/0 result for the marker and ordinary
names. File opening, frame parsing, diagnostics, human-readable formatting,
private file-info storage, and list orchestration remain C-owned. The optional
codec-version helpers remain untouched because their build-time library
configuration is not propagated to the Rust archive.

Test Plan:
- `clang -fsyntax-only -Iprograms -Ilib -Ilib/common -Ilib/compress -Ilib/decompress -Ilib/dictBuilder programs/fileio.c` -- passed.
- `rustfmt --edition 2021 --check --config skip_children=true rust/cli/src/lib.rs` -- passed.
- `git diff --check` and `git diff --cached --check` -- passed.
- Cargo, clippy, native builds, and upstream tests were not run per the explicit no-heavy-command constraint.
2026-07-20 13:37:00 +02:00

70 lines
1.9 KiB
Rust

#[cfg(any(feature = "benchmark", feature = "helpers"))]
#[path = "../../src/benchfn.rs"]
mod benchfn;
#[cfg(feature = "benchmark")]
#[path = "../../src/benchzstd.rs"]
mod benchzstd;
#[cfg(any(feature = "benchmark", feature = "helpers"))]
#[path = "../../src/datagen.rs"]
mod datagen;
#[cfg(all(feature = "cli", feature = "dict-builder"))]
#[path = "../../src/dibio.rs"]
mod dibio;
#[cfg(feature = "cli")]
#[path = "../../src/fileio_backend.rs"]
mod fileio_backend;
#[cfg(feature = "cli")]
#[path = "../../src/fileio_prefs.rs"]
mod fileio_prefs;
#[cfg(any(feature = "benchmark", feature = "helpers"))]
#[path = "../../src/lorem.rs"]
mod lorem;
#[path = "../../src/timefn.rs"]
mod timefn;
#[path = "../../src/util.rs"]
mod util;
#[cfg(feature = "cli")]
#[path = "../../src/zstd_cli.rs"]
mod zstd_cli;
#[cfg(feature = "cli")]
#[path = "../../src/zstdcli_trace.rs"]
mod zstdcli_trace;
#[cfg(feature = "cli")]
use std::ffi::c_void;
#[cfg(feature = "cli")]
use std::os::raw::{c_char, c_int};
/// Match the C `--list` stdin callback without crossing any file-I/O state.
#[cfg(feature = "cli")]
#[no_mangle]
pub unsafe extern "C" fn FIO_listFileIsStdin(
_opaque: *mut c_void,
file_name: *const c_char,
) -> c_int {
assert!(!file_name.is_null());
c_int::from(unsafe { libc::strcmp(file_name, c"/*stdin*\\".as_ptr()) == 0 })
}
#[cfg(all(test, feature = "cli"))]
mod tests {
use super::FIO_listFileIsStdin;
use std::ffi::CString;
use std::ptr;
#[test]
fn list_stdin_callback_matches_only_the_stdin_marker() {
let stdin_name = CString::new("/*stdin*\\").unwrap();
let ordinary_name = CString::new("input.zst").unwrap();
assert_eq!(
unsafe { FIO_listFileIsStdin(ptr::null_mut(), stdin_name.as_ptr()) },
1
);
assert_eq!(
unsafe { FIO_listFileIsStdin(ptr::null_mut(), ordinary_name.as_ptr()) },
0
);
}
}