devela::_dep::nc

Function renameat

pub unsafe fn renameat<P>(
    olddfd: i32,
    oldfilename: P,
    newdfd: i32,
    newfilename: P,
) -> Result<(), i32> 
where P: AsRef<Path>,
Available on crate feature dep_nc only.
Expand description

Change name or location of a file.

§Examples

let path = "/tmp/nc-renameat";
let ret = unsafe { nc::openat(nc::AT_FDCWD, path, nc::O_WRONLY | nc::O_CREAT, 0o644) };
assert!(ret.is_ok());
let fd = ret.unwrap();
let ret = unsafe { nc::close(fd) };
assert!(ret.is_ok());
let new_path = "/tmp/nc-renameat-new";
let ret = unsafe { nc::renameat(nc::AT_FDCWD, path, nc::AT_FDCWD, new_path) };
assert!(ret.is_ok());
let ret = unsafe { nc::unlinkat(nc::AT_FDCWD, new_path, 0) };
assert!(ret.is_ok());