Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/lib/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@ fn remove_dir(p: path) -> bool {
}
}

fn change_dir(p: path) -> bool {
ret chdir(p);

#[cfg(target_os = "win32")]
fn chdir(_p: path) -> bool {
ret str::as_buf(_p, {|buf| os::kernel32::SetCurrentDirectory(buf)});
}

#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
fn chdir(_p: path) -> bool {
ret str::as_buf(_p, {|buf| os::libc::chdir(buf) == 0i32 });
}
}

/*
Function: path_is_absolute

Expand Down
1 change: 1 addition & 0 deletions src/lib/linux_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ native mod libc {
fn readlink(path: str::sbuf, buf: str::sbuf, bufsize: size_t) -> ssize_t;
fn mkdir(path: str::sbuf, mode: c_int) -> c_int;
fn rmdir(path: str::sbuf) -> c_int;
fn chdir(path: str::sbuf) -> c_int;
}

mod libc_constants {
Expand Down
1 change: 1 addition & 0 deletions src/lib/macos_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ native mod libc {
fn waitpid(pid: pid_t, &status: c_int, options: c_int) -> c_int;
fn mkdir(s: str::sbuf, mode: c_int) -> c_int;
fn rmdir(s: str::sbuf) -> c_int;
fn chdir(s: str::sbuf) -> c_int;
}

mod libc_constants {
Expand Down
1 change: 1 addition & 0 deletions src/lib/win32_os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ native mod kernel32 {
fn CreateDirectoryA(lpPathName: LPCTSTR,
lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
fn RemoveDirectoryA(lpPathName: LPCTSTR) -> bool;
fn SetCurrentDirectory(lpPathName: LPCTSTR) -> bool;
}

// FIXME turn into constants
Expand Down