Skip to content

Commit 44c9cf2

Browse files
committed
[library/std pal os]: implemented chdir
1 parent 41f43ba commit 44c9cf2

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

library/std/src/sys/pal/safaos/os.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@ pub fn getcwd() -> io::Result<PathBuf> {
3131
Ok(path)
3232
}
3333

34-
pub fn chdir(_: &path::Path) -> io::Result<()> {
35-
unsupported()
34+
pub fn chdir(path: &path::Path) -> io::Result<()> {
35+
syscalls::chdir(path)?;
36+
Ok(())
3637
}
3738

3839
pub struct SplitPaths<'a>(!, PhantomData<&'a ()>);

library/std/src/sys/pal/safaos/syscalls.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::arch::asm;
22
use crate::os::safaos::errors::{ErrorStatus, SysSuccess};
3+
use crate::path::Path;
34
use core::{ops, ptr};
45

56
/// Keep in sync with the kernel implementition
@@ -212,6 +213,17 @@ pub fn exit(code: usize) -> ! {
212213
unreachable!()
213214
}
214215

216+
#[inline(always)]
217+
fn syschdir(buf: &[u8]) -> Result<SysSuccess, ErrorStatus> {
218+
syscall2(SyscallNum::SysCHDir, buf.as_ptr() as usize, buf.len())
219+
}
220+
221+
#[inline]
222+
pub fn chdir(path: &Path) -> Result<(), ErrorStatus> {
223+
let path = path.as_os_str().as_encoded_bytes();
224+
syschdir(path).map(|SysSuccess| ())
225+
}
226+
215227
/// Gets the current working directory
216228
/// returns Err(ErrorStatus::Generic) if the buffer is too small to hold the cwd
217229
#[inline(always)]

0 commit comments

Comments
 (0)