devela::_dep::nc

Function readlink

pub unsafe fn readlink<P>(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-readlink";
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 ret = unsafe { nc::readlink(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());