about summary refs log tree commit diff
path: root/src/libstd/sys/unix/mod.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-02-10 04:07:03 +0000
committerbors <bors@rust-lang.org>2015-02-10 04:07:03 +0000
commit0bfe358e0fe3b35f0434e81e7c53ea844e95cc13 (patch)
tree091fc970b94cf86a68fd62febef1c5648f5b0d9d /src/libstd/sys/unix/mod.rs
parent134e00be7751a9fdc820981962e4fd7ea97bfff6 (diff)
parent6bfbad937bdf578e35777d079f8dcfab49758041 (diff)
downloadrust-0bfe358e0fe3b35f0434e81e7c53ea844e95cc13.tar.gz
rust-0bfe358e0fe3b35f0434e81e7c53ea844e95cc13.zip
Auto merge of #21936 - alexcrichton:fsv2, r=aturon
This commit is an implementation of [RFC 739][rfc] which adds a new `std::fs`
module to the standard library. This module provides much of the same
functionality as `std::old_io::fs` but it has many tweaked APIs as well as uses
the new `std::path` module.

[rfc]: https://github.com/rust-lang/rfcs/pull/739
Diffstat (limited to 'src/libstd/sys/unix/mod.rs')
-rw-r--r--src/libstd/sys/unix/mod.rs27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs
index 427cf21ac70..b5a24278a20 100644
--- a/src/libstd/sys/unix/mod.rs
+++ b/src/libstd/sys/unix/mod.rs
@@ -23,6 +23,7 @@ use libc;
 use num::{Int, SignedInt};
 use num;
 use old_io::{self, IoResult, IoError};
+use io;
 use str;
 use sys_common::mkerr_libc;
 
@@ -39,9 +40,11 @@ macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => (
 
 pub mod backtrace;
 pub mod c;
-pub mod ext;
 pub mod condvar;
-pub mod fs;
+pub mod ext;
+pub mod fd;
+pub mod fs;  // support for std::old_io
+pub mod fs2; // support for std::fs
 pub mod helper_signal;
 pub mod mutex;
 pub mod os;
@@ -176,6 +179,26 @@ pub fn retry<T, F> (mut f: F) -> T where
     }
 }
 
+pub fn cvt<T: SignedInt>(t: T) -> io::Result<T> {
+    let one: T = Int::one();
+    if t == -one {
+        Err(io::Error::last_os_error())
+    } else {
+        Ok(t)
+    }
+}
+
+pub fn cvt_r<T, F>(mut f: F) -> io::Result<T>
+    where T: SignedInt, F: FnMut() -> T
+{
+    loop {
+        match cvt(f()) {
+            Err(ref e) if e.kind() == ErrorKind::Interrupted => {}
+            other => return other,
+        }
+    }
+}
+
 pub fn ms_to_timeval(ms: u64) -> libc::timeval {
     libc::timeval {
         tv_sec: (ms / 1000) as libc::time_t,