Skip to main content

Crate libbsd_sys

Crate libbsd_sys 

Source
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-dev

On 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

The build script recognizes the following environment variables:

  • LIBBSD_NO_PKG_CONFIG — Set to any value to skip pkg-config entirely. The build script will emit cargo:rustc-link-lib=bsd without any search path. This is useful for running cargo clippy in CI without libbsd-dev installed.

  • LIBBSD_LIB_DIR — Path to the directory containing the libbsd library. Implies LIBBSD_NO_PKG_CONFIG.

  • LIBBSD_INCLUDE_DIR — Path(s) to libbsd headers (colon-separated on Unix). Only used in the manual override path; the include paths are exported as DEP_BSD_INCLUDE for dependent build scripts.

  • LIBBSD_STATIC — Set to 1/true/yes to force static linking, or 0/false/no to force dynamic linking. Overrides the static crate 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 multiple include= lines).

  • DEP_BSD_LIBDIR — Library directory (one path per value).

Structs§

StringList
nlist
pidfh

Enums§

FILE

Constants§

FPARSELN_UNESCALL
FPARSELN_UNESCCOMM
FPARSELN_UNESCCONT
FPARSELN_UNESCESC
FPARSELN_UNESCREST
HN_AUTOSCALE
HN_B
HN_DECIMAL
HN_DIVISOR_1000
HN_GETSCALE
HN_IEC_PREFIXES
HN_NOSPACE
N_ABS
N_BSS
N_COMM
N_DATA
N_EXT
N_FN
N_INDR
N_SETA
N_SETB
N_SETD
N_SETT
N_SETV
N_SIZE
N_STAB
N_TEXT
N_TYPE
N_UNDF
N_WARN
RPP_ECHO_OFF
RPP_ECHO_ON
RPP_FORCELOWER
RPP_FORCEUPPER
RPP_REQUIRE_TTY
RPP_SEVENBIT
RPP_STDIN
UNVIS_END
UNVIS_ERROR
UNVIS_NOCHAR
UNVIS_SYNBAD
UNVIS_VALID
UNVIS_VALIDPUSH
VIS_CSTYLE
VIS_DQ
VIS_GLOB
VIS_HTTP1808
VIS_HTTP1866
VIS_HTTPSTYLE
VIS_META
VIS_MIMESTYLE
VIS_NL
VIS_NOESCAPE
VIS_NOLOCALE
VIS_NOSLASH
VIS_OCTAL
VIS_SAFE
VIS_SHELL
VIS_SP
VIS_TAB
VIS_WHITE

Statics§

optreset

Functions§

arc4random
arc4random_addrandom
arc4random_buf
arc4random_stir
arc4random_uniform
bsd_getopt
closefrom
dehumanize_number
errc
expand_number
explicit_bzero
fgetln
fgetwln
flopen
flopenat
fmtcheck
fparseln
fpurge
freezero
funopen
getbsize
getmode
getpeereid
getprogname
gid_from_group
group_from_gid
heapsort
humanize_number
inet_net_pton
int_to_time
long_to_time
mergesort
nlist
nvis
pidfile_close
pidfile_fileno
pidfile_open
pidfile_remove
pidfile_write
radixsort
readpassphrase
reallocarray
reallocf
recallocarray
setmode
setproctitle
setproctitle_init
setprogname
sl_add
sl_delete
sl_find
sl_free
sl_init
snvis
sradixsort
stravis
strenvisx
strlcat
strlcpy
strmode
strnstr
strnunvis
strnunvisx
strnvis
strnvisx
strsenvisx
strsnvis
strsnvisx
strsvis
strsvisx
strtonum
strunvis
strunvisx
strvis
strvisx
svis
time32_to_time
time64_to_time
time_to_int
time_to_long
time_to_time32
time_to_time64
uid_from_user
unvis
user_from_uid
vis
warnc
wcslcat
wcslcpy

Type Aliases§

c_ulong
Equivalent to C’s unsigned long type.
gid_t
mode_t
off_t
pid_t
size_t
ssize_t
uid_t