Skip to content

passcod/nc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

nc

Build Status Latest version Documentation Minimum rustc version License

Execute system call directly. nc do not depend on std.

Usage

Add this to Cargo.toml:

[dependencies]
nc = "0.5"

Examples

Get file stat:

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

Fork process:

let pid = nc::fork();
match pid {
    Ok(pid) => {
        if pid == 0 {
            println!("parent process!");
        } else if pid < 0 {
            eprintln!("fork() error!");
        } else {
            println!("child process: {}", pid);
            let args = [""];
            let env = [""];
            match nc::execve("/bin/ls", &args, &env) {
                Ok(_) => {},
                Err(errno) => eprintln!("`ls` got err: {}", errno),
            }
        }
    },
    Err(errno) => eprintln!("errno: {}", errno),
}

Kill self:

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

Stable version

For stable version of rustc, please install a C compiler (gcc or clang) first. As asm! feature is unavailable in stable version.

Related projects

License

This library is release in Apache License.

About

Execute syscall call directly

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Rust 97.8%
  • C 1.1%
  • Python 1.1%