Move filename tables, file-list expansion, core-count helpers, statistics, and dictionary sample loading behind Rust implementations while retaining the narrow C ABI used by the CLI. Test Plan: - RUSTC_WRAPPER= CARGO_BUILD_RUSTC_WRAPPER= cargo test --manifest-path rust/cli/Cargo.toml - RUSTC_WRAPPER= CARGO_BUILD_RUSTC_WRAPPER= cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - make -B -C programs zstd V=1 - make -C tests check V=1
62 lines
2.6 KiB
C
62 lines
2.6 KiB
C
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
* in the COPYING file in the root directory of this source tree).
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
*/
|
|
|
|
/* The implementation lives in rust/src/util.rs, built into the Rust CLI
|
|
* static archive. Keep this translation unit in the original C source lists
|
|
* so util.h remains the public C ABI and every program variant still checks
|
|
* the ABI at compile time. */
|
|
|
|
#include "util.h"
|
|
#include <stddef.h>
|
|
|
|
/* These assertions deliberately use the public C declarations rather than a
|
|
* Rust-private mirror. They catch accidental changes to the structures that
|
|
* cross the C/Rust boundary on every supported C build. */
|
|
typedef char UTIL_rust_human_value_offset[
|
|
(offsetof(UTIL_HumanReadableSize_t, value) == 0) ? 1 : -1];
|
|
typedef char UTIL_rust_human_precision_offset[
|
|
(offsetof(UTIL_HumanReadableSize_t, precision) == sizeof(double)) ? 1 : -1];
|
|
typedef char UTIL_rust_human_suffix_offset[
|
|
(offsetof(UTIL_HumanReadableSize_t, suffix)
|
|
>= offsetof(UTIL_HumanReadableSize_t, precision) + sizeof(int)) ? 1 : -1];
|
|
typedef char UTIL_rust_human_size[
|
|
(sizeof(UTIL_HumanReadableSize_t)
|
|
== offsetof(UTIL_HumanReadableSize_t, suffix) + sizeof(const char*)) ? 1 : -1];
|
|
|
|
typedef char UTIL_rust_fnt_file_names_offset[
|
|
(offsetof(FileNamesTable, fileNames) == 0) ? 1 : -1];
|
|
typedef char UTIL_rust_fnt_buf_offset[
|
|
(offsetof(FileNamesTable, buf) == sizeof(const char**)) ? 1 : -1];
|
|
typedef char UTIL_rust_fnt_size_offset[
|
|
(offsetof(FileNamesTable, tableSize)
|
|
== offsetof(FileNamesTable, buf) + sizeof(char*)) ? 1 : -1];
|
|
typedef char UTIL_rust_fnt_capacity_offset[
|
|
(offsetof(FileNamesTable, tableCapacity)
|
|
== offsetof(FileNamesTable, tableSize) + sizeof(size_t)) ? 1 : -1];
|
|
typedef char UTIL_rust_fnt_size[
|
|
(sizeof(FileNamesTable)
|
|
== offsetof(FileNamesTable, tableCapacity) + sizeof(size_t)) ? 1 : -1];
|
|
|
|
/* Windows' CRT does not expose the POSIX utimensat interface. This helper is
|
|
* intentionally the only platform operation retained in this C translation
|
|
* unit; the public UTIL_utime entry point itself is exported by Rust. */
|
|
#if defined(_WIN32)
|
|
# include <sys/utime.h>
|
|
# include <time.h>
|
|
|
|
int UTIL_rust_utime(const char* filename, const stat_t* statbuf)
|
|
{
|
|
struct _utimbuf timebuf;
|
|
timebuf.actime = time(NULL);
|
|
timebuf.modtime = statbuf->st_mtime;
|
|
return _utime(filename, &timebuf);
|
|
}
|
|
#endif
|