devela::_dep::nc

Function read

pub unsafe fn read(fd: i32, buf: &mut [u8]) -> Result<isize, i32> 
Available on crate feature dep_nc only.
Expand description

Read from a file descriptor.

§Examples

let path = "/etc/passwd";
let ret = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_RDONLY, 0) };
assert!(ret.is_ok());
let fd = ret.unwrap();
let mut buf = [0_u8; 4 * 1024];
let ret = unsafe { nc::read(fd, &mut buf) };
assert!(ret.is_ok());
let n_read = ret.unwrap();
assert!(n_read <= buf.len() as nc::ssize_t);
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());