1 unstable release
Uses new Rust 2024
| 0.0.6 | Mar 1, 2026 |
|---|
#328 in Unix APIs
443 downloads per month
Used in 3 crates
(2 directly)
150KB
3.5K
SLoC
Contains (Windows exe, 84KB) winmd/bnd-linux.winmd
bnd-linux
Rust FFI bindings for POSIX and Linux system APIs, generated from C headers via bnd-winmd and windows-bindgen.
Features
Every module is behind a Cargo feature flag — enable only what you need. No features are enabled by default.
POSIX modules (posix_*)
| Feature | Module | Contents |
|---|---|---|
posix_dirent |
libc::posix::dirent |
Directory entries (opendir, readdir, closedir, DT_*) |
posix_dl |
libc::posix::dl |
Dynamic loading (dlopen, dlclose, dlsym, RTLD_*) |
posix_errno |
libc::posix::errno |
Error codes (__errno_location, E* constants) |
posix_fcntl |
libc::posix::fcntl |
File control (creat, lockf, O_* constants) |
posix_inet |
libc::posix::inet |
Internet addresses (inet_pton, htons, sockaddr_in, IPPROTO_*) |
posix_mmap |
libc::posix::mmap |
Memory mapping (mmap, munmap, mprotect, MAP_*/PROT_*) |
posix_netdb |
libc::posix::netdb |
Network database (getaddrinfo, gethostbyname, addrinfo) |
posix_pthread |
libc::posix::pthread |
POSIX threads (pthread_create, pthread_mutex_lock, PTHREAD_*) |
posix_sched |
libc::posix::sched |
Scheduling (sched_yield, sched_setscheduler, SCHED_*) |
posix_signal |
libc::posix::signal |
Signal handling (signal, sigaction, kill, raise, SIG*/SA_*) |
posix_socket |
libc::posix::socket |
Sockets (socket, bind, listen, accept, AF_*/SOCK_*) |
posix_stat |
libc::posix::stat |
File status (stat, chmod, mkdir, struct stat) |
posix_stdio |
libc::posix::stdio |
Standard I/O (fopen, fclose, fread, fwrite) |
posix_time |
libc::posix::time |
Time functions (clock_gettime, nanosleep, gmtime, CLOCK_*) |
posix_types |
libc::posix::types |
Shared POSIX types (uid_t, pid_t, mode_t, off_t, gid_t) |
posix_unistd |
libc::posix::unistd |
POSIX standard (read, write, close, fork) |
Linux modules (linux_*)
| Feature | Module | Contents |
|---|---|---|
linux_epoll |
libc::linux::epoll |
I/O event notification (epoll_create1, epoll_ctl, epoll_wait) |
linux_eventfd |
libc::linux::eventfd |
Event file descriptors (eventfd, eventfd_read, eventfd_write) |
linux_inotify |
libc::linux::inotify |
File system events (inotify_init1, inotify_add_watch) |
linux_mount |
libc::linux::mount |
Mount operations (mount, umount, MS_* flags) |
linux_sendfile |
libc::linux::sendfile |
Zero-copy file transfer (sendfile) |
linux_signalfd |
libc::linux::signalfd |
Signal file descriptors (signalfd, signalfd_siginfo) |
linux_timerfd |
libc::linux::timerfd |
Timer file descriptors (timerfd_create, timerfd_settime) |
linux_types |
libc::linux::types |
Linux-specific types (__be16, __be32, __le*) |
linux_xattr |
libc::linux::xattr |
Extended attributes (setxattr, getxattr, listxattr) |
Usage
Add to Cargo.toml with the features you need:
[dependencies]
bnd-linux = { version = "0.0.1", features = ["posix_socket", "posix_signal", "linux_epoll"] }
Then use the bindings:
use bnd_linux::libc::posix::signal::*;
use bnd_linux::libc::linux::epoll::*;
// All FFI functions are unsafe
let epfd = unsafe { epoll_create1(0) };
assert!(epfd >= 0);
unsafe { raise(0) };
Safety
All function bindings are unsafe — they call directly into C code via
libc. The caller is responsible for upholding the preconditions documented
in the corresponding POSIX/Linux man pages.
Regenerating
The bindings are checked in and generated by bnd-linux-gen:
cargo run -p bnd-linux-gen
Do not edit files under src/libc/ manually — they will be overwritten.
License
MIT