about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2012-03-02 14:49:15 -0800
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2012-03-02 19:15:36 -0800
commit6b0c4822c10d1e0824043f81fc9e39096cc40172 (patch)
treec5437eb193ff236979644eea400afd300a9d557f /src/libstd
parent3cb2cd1f7133619761a7c229185f0ab227526181 (diff)
downloadrust-6b0c4822c10d1e0824043f81fc9e39096cc40172.tar.gz
rust-6b0c4822c10d1e0824043f81fc9e39096cc40172.zip
std: add a fs::remove_file function.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/freebsd_os.rs1
-rw-r--r--src/libstd/fs.rs21
-rw-r--r--src/libstd/linux_os.rs1
-rw-r--r--src/libstd/macos_os.rs1
-rw-r--r--src/libstd/win32_os.rs1
5 files changed, 25 insertions, 0 deletions
diff --git a/src/libstd/freebsd_os.rs b/src/libstd/freebsd_os.rs
index d7ca27b550b..6fbe0b00fde 100644
--- a/src/libstd/freebsd_os.rs
+++ b/src/libstd/freebsd_os.rs
@@ -62,6 +62,7 @@ native mod libc {
     fn mkdir(path: str::sbuf, mode: c_int) -> c_int;
     fn rmdir(path: str::sbuf) -> c_int;
     fn chdir(path: str::sbuf) -> c_int;
+    fn unlink(path: str::sbuf) -> c_int;
 
     fn sysctl(name: *c_int, namelen: c_uint,
               oldp: *u8, &oldlenp: size_t,
diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs
index e97b0a4a56e..767908339a1 100644
--- a/src/libstd/fs.rs
+++ b/src/libstd/fs.rs
@@ -449,6 +449,27 @@ fn homedir() -> option<path> {
     }
 }
 
+/*
+Function: remove_file
+
+Deletes an existing file.
+*/
+fn remove_file(p: path) -> bool {
+    ret unlink(p);
+
+    #[cfg(target_os = "win32")]
+    fn unlink(p: path) -> bool {
+        ret str::as_buf(p, {|buf| os::kernel32::DeleteFileA(buf)});
+    }
+
+    #[cfg(target_os = "linux")]
+    #[cfg(target_os = "macos")]
+    #[cfg(target_os = "freebsd")]
+    fn unlink(_p: path) -> bool {
+        ret str::as_buf(_p, {|buf| os::libc::unlink(buf) == 0i32 });
+    }
+}
+
 #[cfg(test)]
 mod tests {
     #[test]
diff --git a/src/libstd/linux_os.rs b/src/libstd/linux_os.rs
index 0231add3cd4..bfbbaf52ff2 100644
--- a/src/libstd/linux_os.rs
+++ b/src/libstd/linux_os.rs
@@ -63,6 +63,7 @@ native mod libc {
     fn mkdir(path: str::sbuf, mode: c_int) -> c_int;
     fn rmdir(path: str::sbuf) -> c_int;
     fn chdir(path: str::sbuf) -> c_int;
+    fn unlink(path: str::sbuf) -> c_int;
 }
 
 mod libc_constants {
diff --git a/src/libstd/macos_os.rs b/src/libstd/macos_os.rs
index e44bc4c20e2..bb9efdcbc09 100644
--- a/src/libstd/macos_os.rs
+++ b/src/libstd/macos_os.rs
@@ -55,6 +55,7 @@ native mod libc {
     fn mkdir(s: str::sbuf, mode: c_int) -> c_int;
     fn rmdir(s: str::sbuf) -> c_int;
     fn chdir(s: str::sbuf) -> c_int;
+    fn unlink(path: str::sbuf) -> c_int;
 
     // FIXME: Needs varags
     fn fcntl(fd: fd_t, cmd: c_int) -> c_int;
diff --git a/src/libstd/win32_os.rs b/src/libstd/win32_os.rs
index aa589cf3c32..74de2c14668 100644
--- a/src/libstd/win32_os.rs
+++ b/src/libstd/win32_os.rs
@@ -62,6 +62,7 @@ native mod kernel32 {
                         lpSecurityAttributes: LPSECURITY_ATTRIBUTES) -> bool;
     fn RemoveDirectoryA(lpPathName: LPCTSTR) -> bool;
     fn SetCurrentDirectoryA(lpPathName: LPCTSTR) -> bool;
+    fn DeleteFileA(lpFileName: LPCTSTR) -> bool;
 }
 
 // FIXME turn into constants