about summary refs log tree commit diff
path: root/src/lib
diff options
context:
space:
mode:
authorElly Jones <elly@leptoquark.net>2011-12-01 22:19:10 -0500
committerElly Jones <elly@leptoquark.net>2011-12-01 22:19:53 -0500
commit9b3f8bf2a9a78ab41f6dc112162a64287ce56d89 (patch)
treef63d0a5cb181b779083f2f6a0d5d308cb11bc647 /src/lib
parent1974cf9a817455fb3dda94f6bb6ad7c85647260c (diff)
downloadrust-9b3f8bf2a9a78ab41f6dc112162a64287ce56d89.tar.gz
rust-9b3f8bf2a9a78ab41f6dc112162a64287ce56d89.zip
libstd: add fs::change_dir()
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/fs.rs15
-rw-r--r--src/lib/linux_os.rs1
-rw-r--r--src/lib/macos_os.rs1
-rw-r--r--src/lib/win32_os.rs1
4 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/fs.rs b/src/lib/fs.rs
index de5bae0b50b..945a0a32c7b 100644
--- a/src/lib/fs.rs
+++ b/src/lib/fs.rs
@@ -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
 
diff --git a/src/lib/linux_os.rs b/src/lib/linux_os.rs
index de655b5c12c..a2dc0e8632a 100644
--- a/src/lib/linux_os.rs
+++ b/src/lib/linux_os.rs
@@ -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 {
diff --git a/src/lib/macos_os.rs b/src/lib/macos_os.rs
index 2bd5eab93ba..ad90fef489e 100644
--- a/src/lib/macos_os.rs
+++ b/src/lib/macos_os.rs
@@ -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 {
diff --git a/src/lib/win32_os.rs b/src/lib/win32_os.rs
index 4b5635020d9..5099b7716d6 100644
--- a/src/lib/win32_os.rs
+++ b/src/lib/win32_os.rs
@@ -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