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:

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 { libc::sysconf(libc::_SC_PAGESIZE) };
assert!(page_size > 0);

let uid = unsafe { libc::getuid() };
let pid = unsafe { libc::getpid() };
assert!(pid > 0);