nc 0.4.2

Execute system call directly
docs.rs failed to build nc-0.4.2
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: nc-0.8.20

nc

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

Usage

Add this to Cargo.toml:

[dependencies]
nc = "0.4.2"

And add this to crate code:

extern crate nc;

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 = c::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);

Related projects

License

This library is release in Apache License.