devela::_dep::nc

Function readlinkat

pub unsafe fn readlinkat<P>(
    dirfd: i32,
    filename: P,
    buf: &mut [u8],
) -> Result<isize, i32> 
where P: AsRef<Path>,
Available on crate feature dep_nc only.
Expand description

Read value of a symbolic link.

§Examples

let oldname = "/etc/passwd";
let newname = "/tmp/nc-readlinkat";
let ret = unsafe { nc::symlinkat(oldname, nc::AT_FDCWD, newname) };
assert!(ret.is_ok());
let mut buf = [0_u8; nc::PATH_MAX as usize + 1];
let buf_len = buf.len();
let ret = unsafe { nc::readlinkat(nc::AT_FDCWD, newname, &mut buf) };
assert!(ret.is_ok());
let n_read = ret.unwrap() as usize;
assert_eq!(n_read, oldname.len());
assert_eq!(oldname.as_bytes(), &buf[0..n_read]);
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, newname, 0) };
assert!(ret.is_ok());