#api #file #network


Safe Rust bindings to POSIX-ish libc APIs and syscalls

54 releases (16 breaking)

new 0.16.4 Jul 21, 2021
0.15.5 Jul 6, 2021
0.6.1 Mar 2, 2021
0.5.2 Dec 8, 2020
0.4.1 Oct 27, 2020

#21 in Unix APIs

Download history 1520/week @ 2021-04-04 1994/week @ 2021-04-11 1029/week @ 2021-04-18 912/week @ 2021-04-25 1511/week @ 2021-05-02 2128/week @ 2021-05-09 2446/week @ 2021-05-16 1934/week @ 2021-05-23 1994/week @ 2021-05-30 1411/week @ 2021-06-06 2886/week @ 2021-06-13 3302/week @ 2021-06-20 2978/week @ 2021-06-27 1774/week @ 2021-07-04 3156/week @ 2021-07-11 2716/week @ 2021-07-18

9,417 downloads per month
Used in 36 crates (14 directly)

Apache-2.0 WITH LLVM-exception OR Apache-2.0 OR MIT

15K SLoC


Safe Rust bindings to POSIX-ish libc APIs and syscalls

A Bytecode Alliance project

Github Actions CI Status crates.io page docs.rs docs

posish provides efficient memory-safe and I/O-safe wrappers to "POSIX-ish" libc APIs and syscalls, with configurable backends. It uses Rust references, slices, and return values instead of raw pointers, and io-lifetimes instead of raw file descriptors, providing memory safety and I/O safety. It uses Results for reporting errors, bitflags instead of bare integer flags, an Arg trait with optimizations to efficiently accept any Rust string type, and several other efficient conveniences.

posish is low-level and does not support Windows; for higher-level and more portable APIs built on this functionality, see the system-interface, cap-std, and fs-set-times crates, for example.

Posish currently has two backends available: libc and linux_raw.

The linux_raw backend is enabled by default on Linux on x86-64, x86, aarch64, and riscv64gc, and uses raw Linux system calls and vDSO calls. It supports stable as well as nightly Rust.

  • By being implemented entirely in Rust, avoiding libc, errno, and pthread cancellation, and employing some specialized optimizations, most functions compile down to very efficient code. On nightly Rust, they can often be fully inlined into user code.
  • Most functions in linux_raw preserve memory and I/O safety all the way down to the syscalls.
  • linux_raw uses a 64-bit time_t type on all platforms, avoiding the y2038 bug.

The libc backend is enabled by default on all other platforms, and can be explicitly for any target by setting RUSTFLAGS to --cfg posish_use_libc. It uses the libc crate which provides bindings to native libc libraries and is portable to many OS's.


~56K SLoC