devela::_dep::nc

Function link

pub unsafe fn link<P>(old_filename: P, new_filename: P) -> Result<(), i32> 
where P: AsRef<Path>,
Available on crate feature dep_nc only.
Expand description

Make a new name for a file.

§Examples

let old_filename = "/tmp/nc-link-src";
let ret = unsafe {
    nc::openat(
        nc::AT_FDCWD,
        old_filename,
        nc::O_CREAT | nc::O_WRONLY | nc::O_TRUNC,
        0o644
    )
};
assert!(ret.is_ok());
let fd = ret.unwrap();
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());
let new_filename = "/tmp/nc-link-dst";
let ret = unsafe { nc::link(old_filename, new_filename) };
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, old_filename, 0) };
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, new_filename, 0) };
assert!(ret.is_ok());