about summary refs log tree commit diff
path: root/src/libstd/os.rs
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2013-08-28 12:27:10 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2013-08-30 15:48:37 -0700
commit34ed4e26a2c08edc50bb797170212daaad048e46 (patch)
tree6ee791b15ee0acd40c0b841d7571ad19dd6c7e86 /src/libstd/os.rs
parent8464ee04a423808bf110640adf5c9c4952b1f9cf (diff)
downloadrust-34ed4e26a2c08edc50bb797170212daaad048e46.tar.gz
rust-34ed4e26a2c08edc50bb797170212daaad048e46.zip
std: Add a file-renaming function to std::os
Diffstat (limited to 'src/libstd/os.rs')
-rw-r--r--src/libstd/os.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 07e0b0857a1..91408162788 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -1002,6 +1002,18 @@ pub fn remove_file(p: &Path) -> bool {
     }
 }
 
+/// Renames an existing file or directory
+pub fn rename_file(old: &Path, new: &Path) -> bool {
+    #[fixed_stack_segment]; #[inline(never)];
+    unsafe {
+       do old.with_c_str |old_buf| {
+            do new.with_c_str |new_buf| {
+                libc::rename(old_buf, new_buf) == (0 as c_int)
+            }
+       }
+    }
+}
+
 #[cfg(unix)]
 /// Returns the platform-specific value of errno
 pub fn errno() -> int {