Module libc
Raw FFI bindings to platform-specific system libraries.
libc provides raw bindings to the C standard library
and platform-specific system APIs.
It is the foundational crate for most Rust FFI that
needs to interoperate with system and native libraries.
The crate exports types, constants, and function signatures matching the platform's C headers. On Linux this includes POSIX APIs and Linux-specific extensions; on macOS, the Darwin system APIs; on Windows, a small subset of CRT functions.
Common uses include:
- Calling POSIX functions like
open,read,write,mmap - Accessing system constants like
EINVAL,O_RDONLY,SIGTERM - Defining types for FFI function signatures (
c_int,c_char,size_t) - Low-level memory operations like
mallocandfree
Note that basic C type aliases like c_int and c_char
are available directly in std::ffi.
The nix
and rustix
crates provide additional high-level safe Unix API bindings.
For Windows, the windows
and windows-sys crates
provide bindings to the Win32 API.
Examples
Querying system configuration not exposed by std:
let page_size = unsafe ;
assert!;
let uid = unsafe ;
let pid = unsafe ;
assert!;