Expand description
Raw FFI bindings to libbsd.
This crate provides extern "C" declarations for the functions and types
exported by libbsd, a library that
provides commonly-used BSD functions on GNU/Linux systems.
§Platform support
On macOS, FreeBSD, OpenBSD, and NetBSD, most of these functions are already part of the system C library, so no additional library is needed.
On Linux, the crate uses pkg-config at build time to locate libbsd.
On Debian/Ubuntu, install the development headers with:
apt install libbsd-devOn Windows and other unsupported platforms, this crate is empty.
§Conditional compilation
Functions that only exist in libbsd (not on any BSD natively) are gated
behind #[cfg(target_os = "linux")]. Functions available on the BSDs but
not macOS are gated behind #[cfg(not(target_os = "macos"))].
The strnvis and strnunvis functions have different parameter orders
depending on whether the platform follows the NetBSD convention (macOS,
NetBSD, OpenBSD) or the FreeBSD convention (FreeBSD, Linux/libbsd).
§Environment variables
If pkg-config can’t find libbsd, the build script emits a
cargo:warning and skips the link step rather than aborting. This
lets cargo clippy and cargo check in downstream crates succeed
without libbsd-dev installed; only a real binary build that
references libbsd symbols will fail at link time.
The build script also recognizes the following environment variables:
-
LIBBSD_NO_PKG_CONFIG— Set to any value to skippkg-configprobing, matching the pkg-config-rs convention. On its own, the build script emits norustc-link-libdirective at all. To produce a working binary in this mode, either setLIBBSD_LIB_DIRor arrange linkage yourself (e.g. viaRUSTFLAGS="-l bsd"). -
LIBBSD_LIB_DIR— Path to the directory containing the libbsd library. Skipspkg-configand emits a search path plusrustc-link-libdirective pointing at this directory. -
LIBBSD_INCLUDE_DIR— Path(s) to libbsd headers (colon-separated on Unix). Only used in the manual override path; the include paths are exported asDEP_BSD_INCLUDEfor dependent build scripts. -
LIBBSD_STATIC— Set to1/true/yesto force static linking, or0/false/noto force dynamic linking. Overrides thestaticcrate feature when set. -
DOCS_RS— When set (as it is automatically on docs.rs), the build script skips all linking. This allows documentation builds to succeed without libbsd installed.
§Metadata for dependent crates
This crate sets links = "bsd" in Cargo.toml, so dependent crates’
build scripts can read the following metadata via DEP_BSD_* environment
variables:
-
DEP_BSD_INCLUDE— Include paths for libbsd headers (one path per value; there may be multipleinclude=lines). -
DEP_BSD_LIBDIR— Library directory (one path per value).