fts-sys-0.2.11/.cargo_vcs_info.json0000644000000001360000000000100125250ustar { "git": { "sha1": "e9b71b3c59b7555b8bab2c495df1563028a77672" }, "path_in_vcs": "" }fts-sys-0.2.11/.gitignore000064400000000000000000000000701046102023000133020ustar 00000000000000/target Cargo.lock *.code-workspace .directory *.tar.gz fts-sys-0.2.11/CHANGELOG.md000064400000000000000000000024721046102023000131330ustar 00000000000000# Change log This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [0.2.11] - 2024-09-12 ### Changed - Add support for cross-compilation. - The `clang` parameter `--target=` is passed to `bindgen`. - If one of the environment variables `SYSROOT`, `TARGET_SYSROOT`, `SYSROOT_` or `SYSROOT_` is defined, then the `clang` parameter `--sysroot=` is passed to `bindgen`. ## [0.2.10] - 2024-09-12 ### Changed - Updated dependencies. ## [0.2.9] - 2024-03-27 ### Changed - Moved repository to `codeberg.org`. ## [0.2.8] - 2024-01-19 ### Changed - Updated dependencies. ## [0.2.7] - 2023-10-31 ### Changed - Updated dependencies. ## [0.2.6] - 2023-06-07 ### Changed - Updated build script to better integrate with `cargo`. ## [0.2.5] - 2023-04-18 ### Changed - Updated dependencies. ## [0.2.4] - 2022-11-22 ### Changed - Updated dependencies. ## [0.2.3] - 2022-11-20 ### Changed - Updated dependencies. ## [0.2.2] - 2022-09-03 ### Changed - Updated Rust edition to 2021. - Updated dependencies. ## [0.2.1] - 2021-07-28 ### Changed - Updated dependencies. ## [0.2.0] - 2021-04-17 ### Changed - Building for non-UNIX platforms is now supported, but it results in an empty crate. ## [0.1.0] - 2021-03-06 ### Added - Initial release. fts-sys-0.2.11/Cargo.toml0000644000000023060000000000100105240ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "fts-sys" version = "0.2.11" authors = ["Koutheir Attouchi "] build = "build.rs" links = "c" autobins = false autoexamples = false autotests = false autobenches = false description = "File hierarchy traversal functions (FTS)" homepage = "https://codeberg.org/koutheir/fts-sys.git" documentation = "https://docs.rs/fts-sys" readme = "README.md" keywords = [ "fts", "filesystem", "tree", "hierarchy", ] categories = [ "external-ffi-bindings", "filesystem", ] license = "MIT" repository = "https://codeberg.org/koutheir/fts-sys.git" [lib] name = "fts_sys" path = "src/lib.rs" [build-dependencies.bindgen] version = "0.70" [target."cfg(unix)".dependencies.libc] version = "0.2" fts-sys-0.2.11/Cargo.toml.orig000064400000000000000000000013751046102023000142120ustar 00000000000000[package] name = "fts-sys" description = "File hierarchy traversal functions (FTS)" version = "0.2.11" # Remember to update `html_root_url`. authors = ["Koutheir Attouchi "] edition = "2021" readme = "README.md" license = "MIT" keywords = ["fts", "filesystem", "tree", "hierarchy"] categories = ["external-ffi-bindings", "filesystem"] build = "build.rs" links = "c" documentation = "https://docs.rs/fts-sys" homepage = "https://codeberg.org/koutheir/fts-sys.git" repository = "https://codeberg.org/koutheir/fts-sys.git" [target.'cfg(unix)'.dependencies] libc = { version = "0.2" } [build-dependencies] bindgen = { version = "0.70" } fts-sys-0.2.11/LICENSE.txt000064400000000000000000000021151046102023000131370ustar 00000000000000MIT License Copyright (c) 2021-2024 Koutheir Attouchi. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. fts-sys-0.2.11/README.md000064400000000000000000000011631046102023000125750ustar 00000000000000[![crates.io](https://img.shields.io/crates/v/fts-sys.svg)](https://crates.io/crates/fts-sys) [![docs.rs](https://docs.rs/fts-sys/badge.svg)](https://docs.rs/fts-sys) [![license](https://img.shields.io/github/license/koutheir/fts-sys?color=black)](https://raw.githubusercontent.com/koutheir/fts-sys/master/LICENSE.md) # `fts-sys`: Unsafe Rust bindings for FTS functions provided by `libc` The FTS functions enable traversing file hierarchies. ## Versioning This project adheres to [Semantic Versioning]. The `CHANGELOG.md` file details notable changes over time. [Semantic Versioning]: https://semver.org/spec/v2.0.0.html fts-sys-0.2.11/build.rs000064400000000000000000000072301046102023000127640ustar 00000000000000use std::env; use std::ffi::{OsStr, OsString}; use std::path::{Path, PathBuf}; fn main() { let target = env::var("TARGET").expect("selinux-sys: Environment variable 'TARGET' was not defined."); match get_target_os(&target).as_deref() { None => return, // Do not build anything for bare metal architectures. Some("linux") | Some("android") | Some("androideabi") | Some("dragonfly") | Some("freebsd") | Some("netbsd") | Some("openbsd") => { // Continue, probably supported. } _ => return, // Do not build anything, probably unsupported. } let out_dir = env::var_os("OUT_DIR") .map(PathBuf::from) .expect("fts-sys: Environment variable 'OUT_DIR' was not defined."); println!("cargo:root={}", out_dir.to_str().unwrap()); let sysroot = target_env_var_os("SYSROOT", &target).map(PathBuf::from); generate_bindings(&target, sysroot.as_deref(), &out_dir) } fn target_env_var_os(name: &str, target: &str) -> Option { rerun_if_env_changed(name, target); let target_underscores = target.replace('-', "_"); env::var_os(format!("{name}_{target}")) .or_else(|| env::var_os(format!("{name}_{target_underscores}"))) .or_else(|| env::var_os(format!("TARGET_{name}"))) .or_else(|| env::var_os(name)) } fn rerun_if_env_changed(name: &str, target: &str) { let target_underscores = target.replace('-', "_"); println!("cargo:rerun-if-env-changed={name}_{target}"); println!("cargo:rerun-if-env-changed={name}_{target_underscores}"); println!("cargo:rerun-if-env-changed=TARGET_{name}"); println!("cargo:rerun-if-env-changed={name}"); } fn get_target_os(target: &str) -> Option { let components: Vec<_> = target.split('-').collect(); let os_index = match components.len() { 2 => { // e.g., aarch64-fuchsia, wasm32-wasi, x86_64-fuchsia if components[1] == "none" { return None; // Bare metal target. } 1 } 3 | 4 => { // e.g., aarch64-unknown-freebsd, aarch64-unknown-linux-gnu if components[1] == "none" || components[2] == "none" { return None; // Bare metal target. } 2 } _ => panic!("Unrecognized target triplet '{target}'"), }; Some(String::from(components[os_index])) } fn generate_bindings(target: &str, sysroot: Option<&Path>, out_dir: &Path) { let mut builder = bindgen::Builder::default() .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .default_enum_style(bindgen::EnumVariation::ModuleConsts) .default_macro_constant_type(bindgen::MacroTypeVariation::Signed) .size_t_is_usize(true) .derive_debug(true) .derive_copy(true) .impl_debug(true) //.clang_arg("-D_FILE_OFFSET_BITS=64") .clang_arg(format!("--target={target}")); if let Some(sysroot) = sysroot.map(Path::as_os_str).map(OsStr::to_str) { let sysroot = sysroot.expect("SYSROOT is not encoded in UTF-8"); builder = builder.clang_arg(format!("--sysroot={sysroot}")); } builder = builder .allowlist_function("fts_(open|read|children|set|close)") .allowlist_type("FTSENT") .blocklist_type("__.+") .blocklist_type("(FTS|stat|timespec|dev_t|ino_t|nlink_t)") .allowlist_var("FTS_.+") .header("src/fts-sys.h"); let bindings = builder .generate() .expect("fts-sys: Failed to generate Rust bindings for 'fts.h'."); bindings .write_to_file(out_dir.join("fts-sys.rs")) .expect("fts-sys: Failed to write 'fts-sys.rs'.") } fts-sys-0.2.11/src/fts-sys.h000064400000000000000000000000761046102023000136700ustar 00000000000000#include #include #include fts-sys-0.2.11/src/lib.rs000064400000000000000000000007471046102023000132300ustar 00000000000000#![doc = include_str!("../README.md")] #![cfg(unix)] #![doc(html_root_url = "https://docs.rs/fts-sys/0.2.11")] #![warn(unsafe_op_in_unsafe_fn)] #![allow( non_upper_case_globals, non_camel_case_types, non_snake_case, clippy::redundant_static_lifetimes )] #[cfg(test)] mod tests; use libc::dev_t; use libc::ino_t; use libc::nlink_t; use libc::stat; #[repr(C)] #[derive(Debug)] pub struct FTS { _unused: [u8; 0], } include!(concat!(env!("OUT_DIR"), "/fts-sys.rs")); fts-sys-0.2.11/src/tests.rs000064400000000000000000000014271046102023000136200ustar 00000000000000use std::os::raw::c_char; use std::ptr; #[test] fn fts_open() { let paths: [*const c_char; 2] = ["/\0".as_ptr().cast(), ptr::null()]; let fts = unsafe { super::fts_open(paths.as_ptr().cast(), super::FTS_PHYSICAL, None) }; assert_ne!(fts, ptr::null_mut()); unsafe { super::fts_close(fts) }; } #[test] fn fts_read() { let paths: [*const c_char; 2] = ["/\0".as_ptr().cast(), ptr::null()]; let fts = unsafe { super::fts_open(paths.as_ptr().cast(), super::FTS_PHYSICAL, None) }; assert_ne!(fts, ptr::null_mut()); let entry = unsafe { super::fts_read(fts) }; assert_ne!(entry, ptr::null_mut()); if let Some(entry) = unsafe { entry.as_ref() } { assert_ne!(entry.fts_name.as_ptr(), ptr::null_mut()); } unsafe { super::fts_close(fts) }; }