77 releases

Uses new Rust 2024

0.9.8 Jun 3, 2026
0.9.7 Nov 21, 2025
0.9.6 Apr 2, 2025
0.9.5 Oct 18, 2024
0.1.0 Jul 26, 2019

#15 in No standard library

Download history 8050/week @ 2026-02-25 8126/week @ 2026-03-04 8031/week @ 2026-03-11 6388/week @ 2026-03-18 7260/week @ 2026-03-25 5326/week @ 2026-04-01 6892/week @ 2026-04-08 10249/week @ 2026-04-15 8085/week @ 2026-04-22 11558/week @ 2026-04-29 11141/week @ 2026-05-06 16033/week @ 2026-05-13 12906/week @ 2026-05-20 11246/week @ 2026-05-27 9153/week @ 2026-06-03 8990/week @ 2026-06-10

45,057 downloads per month
Used in 13 crates (5 directly)

Apache-2.0

5.5MB
75K SLoC

nc

Build status Latest version Documentation Minimum rustc version License

Access system calls directly without std or libc.

Features:

  • No glibc or musl required
  • Access syscalls directly, via assembly
  • No global errno variable, every function returns an errno instead
  • Support latest kernel APIs, like io-uring and pidfd, introduced in linux 5.0+

Usage

Add this to Cargo.toml:

[dependencies]
nc = "0.9"

Examples

Get file stat:

let mut statbuf = nc::stat_t::default();
match unsafe { nc::stat("/etc/passwd", &mut statbuf) } {
    Ok(_) => println!("s: {:?}", statbuf),
    Err(errno) => eprintln!("Failed to get file status, got errno: {}", errno),
}

Get human-readable error string:

let errno = nc::EPERM;
println!("err: {:?}", nc::strerror(errno);

Fork process:

let pid = unsafe { nc::fork() };
match pid {
    Err(errno) => eprintln!("Failed to call fork(), err: {}", nc::strerror(errno)),
    Ok(0) => {
        // Child process
        println!("[child] pid: {}", unsafe { nc::getpid() });
        let args = ["ls", "-l", "-a"];
        let env = ["DISPLAY=wayland"];
        let ret = unsafe { nc::execve("/bin/ls", &args, &env) };
        assert!(ret.is_ok());
    }
    Ok(child_pid) => {
        // Parent process
        println!("[main] child pid is: {child_pid}");
    }
}

Kill self:

let pid = unsafe { nc::getpid() };
let ret = unsafe { nc::kill(pid, nc::SIGTERM) };
// Never reach here.
println!("ret: {:?}", ret);

Or handle signals:

fn handle_alarm(signum: i32) {
    assert_eq!(signum, nc::SIGALRM);
}

fn main() {
    let sa = nc::new_sigaction(handle_alarm);
    let ret = unsafe { nc::rt_sigaction(nc::SIGALRM, Some(&sa), None) };
    assert!(ret.is_ok());
    let remaining = unsafe { nc::alarm(1) };
    let mask = nc::sigset_t::default();
    let ret = unsafe { nc::rt_sigsuspend(&mask) };
    assert!(ret.is_err());
    assert_eq!(ret, Err(nc::EINTR));
    assert_eq!(remaining, Ok(0));
}

Supported Operating Systems and Architectures

  • linux
    • aarch64
    • arm
    • loongarch64
    • mips
    • mips64
    • mips64el
    • mipsel
    • powerpc64
    • powerpc64el
    • riscv64
    • s390x
    • x86
    • x86-64
  • android
    • aarch64
  • freebsd
    • x86-64
  • netbsd
    • x86-64
  • mac os
    • x86-64

License

nc is Apache-2.0 Licensed.

No runtime deps