devela::_dep::nc

Function chdir

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

Change working directory.

§Examples

let path = "/tmp";
// Open folder directly.
let ret = unsafe { nc::chdir(path) };
assert!(ret.is_ok());

let mut buf = [0_u8; nc::PATH_MAX as usize + 1];
let ret = unsafe { nc::getcwd(&mut buf) };
assert!(ret.is_ok());
// Remove null-terminal char.
let path_len = ret.unwrap() as usize - 1;
let new_cwd = std::str::from_utf8(&buf[..path_len]);
assert_eq!(new_cwd, Ok(path));