Crates.io | libc_tools |
lib.rs | libc_tools |
version | 0.1.3 |
source | src |
created_at | 2021-07-18 10:13:49.62535 |
updated_at | 2021-07-29 01:50:08.645768 |
description | a fork to std process |
homepage | |
repository | |
max_upload_size | |
id | 424348 |
size | 26,964 |
this crate wrapper some sys_call in libc
thanks to libc this crate has some wrapper for libc: fork eg:
match Fork::fork() {
ForkPid::Parent((parent, children)) => {}
ForkPid::Children((parent, children)) => {}
ForkPid::None => panic!("fork failed!")
}
forkpt dup dup2(and dup2s for mutliply fd)
let x : () = Dup::dup2s(&[...olds], &[...news]).unwrap();
popen how to use
unsafe {
let popen = Popen::arg("date").exec().unwrap();
let mut buf = [0 as u8; 4096];
let mut p;
while {
p = fgets(buf.as_mut_ptr() as *mut i8, 4096, popen.stdout);
p != std::ptr::null_mut::<i8>() && *p != '\0' as i8
} {
assert!(strlen(p) != 0);
}
println!("");
while {
p = fgets(buf.as_mut_ptr() as *mut i8, 4096, popen.stderr);
p != std::ptr::null_mut::<i8>() && *p != '\0' as i8
} {
assert!(strlen(p) != 0);
}
}