Function nc::fstat

source ·
pub unsafe fn fstat(fd: i32, statbuf: &mut stat_t) -> Result<(), Errno>
Expand description

Get file status about a file descriptor.

§example

let path = "/tmp";
// Open folder directly.
let fd = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_PATH, 0) };
assert!(fd.is_ok());
let fd = fd.unwrap();
let mut stat = nc::stat_t::default();
let ret = unsafe { nc::fstat(fd, &mut stat) };
assert!(ret.is_ok());
// Check fd is a directory.
assert_eq!((stat.st_mode & nc::S_IFMT), nc::S_IFDIR);
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());