pub unsafe fn write(
fd: int,
buf: *const c_void,
count: size_t,
) -> Result<ssize_t>
Expand description
Write to a file descriptor.
Examples found in repository?
examples/getpid.rs (line 9)
1fn main() {
2 let pid = unsafe { linux_unsafe::getpid() };
3
4 let msg = format!("{}\n", pid);
5 let msg_raw = msg.as_bytes();
6 let msg_ptr = msg_raw.as_ptr() as *const linux_unsafe::void;
7 let msg_size = msg_raw.len() * core::mem::size_of::<u8>();
8
9 let written = unsafe { linux_unsafe::write(1, msg_ptr, msg_size) }.unwrap();
10 if written < 0 {
11 panic!("failed to write");
12 }
13}