diff options
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/fs2.rs | 33 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/pipe.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 16 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process2.rs | 11 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tcp.rs | 6 | 
6 files changed, 50 insertions, 26 deletions
| diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index 92a47c6c385..c6b9c2cba52 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -18,7 +18,7 @@ use libc::{self, c_int, c_void, size_t, off_t, c_char, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; -use rc::Rc; +use sync::Arc; use sys::fd::FileDesc; use sys::{c, cvt, cvt_r}; use sys_common::FromInner; @@ -31,14 +31,18 @@ pub struct FileAttr { } pub struct ReadDir { - dirp: *mut libc::DIR, - root: Rc<PathBuf>, + dirp: Dir, + root: Arc<PathBuf>, } +struct Dir(*mut libc::DIR); + +unsafe impl Send for Dir {} +unsafe impl Sync for Dir {} + pub struct DirEntry { - buf: Vec<u8>, - dirent: *mut libc::dirent_t, - root: Rc<PathBuf>, + buf: Vec<u8>, // actually *mut libc::dirent_t + root: Arc<PathBuf>, } #[derive(Clone)] @@ -109,7 +113,7 @@ impl Iterator for ReadDir { let mut entry_ptr = ptr::null_mut(); loop { - if unsafe { libc::readdir_r(self.dirp, ptr, &mut entry_ptr) != 0 } { + if unsafe { libc::readdir_r(self.dirp.0, ptr, &mut entry_ptr) != 0 } { return Some(Err(Error::last_os_error())) } if entry_ptr.is_null() { @@ -118,7 +122,6 @@ impl Iterator for ReadDir { let entry = DirEntry { buf: buf, - dirent: entry_ptr, root: self.root.clone() }; if entry.name_bytes() == b"." || entry.name_bytes() == b".." { @@ -130,9 +133,9 @@ impl Iterator for ReadDir { } } -impl Drop for ReadDir { +impl Drop for Dir { fn drop(&mut self) { - let r = unsafe { libc::closedir(self.dirp) }; + let r = unsafe { libc::closedir(self.0) }; debug_assert_eq!(r, 0); } } @@ -147,9 +150,13 @@ impl DirEntry { fn rust_list_dir_val(ptr: *mut libc::dirent_t) -> *const c_char; } unsafe { - CStr::from_ptr(rust_list_dir_val(self.dirent)).to_bytes() + CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes() } } + + fn dirent(&self) -> *mut libc::dirent_t { + self.buf.as_ptr() as *mut _ + } } impl OpenOptions { @@ -279,14 +286,14 @@ pub fn mkdir(p: &Path) -> io::Result<()> { } pub fn readdir(p: &Path) -> io::Result<ReadDir> { - let root = Rc::new(p.to_path_buf()); + let root = Arc::new(p.to_path_buf()); let p = try!(cstr(p)); unsafe { let ptr = libc::opendir(p.as_ptr()); if ptr.is_null() { Err(Error::last_os_error()) } else { - Ok(ReadDir { dirp: ptr, root: root }) + Ok(ReadDir { dirp: Dir(ptr), root: root }) } } } diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index b79ad7031fa..632270bc5cc 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -214,9 +214,9 @@ pub fn wouldblock() -> bool { err == libc::EWOULDBLOCK as i32 || err == libc::EAGAIN as i32 } -pub fn set_nonblocking(fd: sock_t, nb: bool) -> IoResult<()> { +pub fn set_nonblocking(fd: sock_t, nb: bool) { let set = nb as libc::c_int; - mkerr_libc(retry(|| unsafe { c::ioctl(fd, c::FIONBIO, &set) })) + mkerr_libc(retry(|| unsafe { c::ioctl(fd, c::FIONBIO, &set) })).unwrap(); } // nothing needed on unix platforms diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 3c9cdc65975..1446600a77e 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -235,9 +235,9 @@ impl UnixListener { _ => { let (reader, writer) = try!(unsafe { sys::os::pipe() }); - try!(set_nonblocking(reader.fd(), true)); - try!(set_nonblocking(writer.fd(), true)); - try!(set_nonblocking(self.fd(), true)); + set_nonblocking(reader.fd(), true); + set_nonblocking(writer.fd(), true); + set_nonblocking(self.fd(), true); Ok(UnixAcceptor { inner: Arc::new(AcceptorInner { listener: self, diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 2be841989e6..68c5c65e7cd 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -69,7 +69,6 @@ impl Process { K: BytesContainer + Eq + Hash, V: BytesContainer { use libc::funcs::posix88::unistd::{fork, dup2, close, chdir, execvp}; - use libc::funcs::bsd44::getdtablesize; mod rustrt { extern { @@ -82,6 +81,15 @@ impl Process { assert_eq!(ret, 0); } + #[cfg(all(target_os = "android", target_arch = "aarch64"))] + unsafe fn getdtablesize() -> c_int { + libc::sysconf(libc::consts::os::sysconf::_SC_OPEN_MAX) as c_int + } + #[cfg(not(all(target_os = "android", target_arch = "aarch64")))] + unsafe fn getdtablesize() -> c_int { + libc::funcs::bsd44::getdtablesize() + } + let dirp = cfg.cwd().map(|c| c.as_ptr()).unwrap_or(ptr::null()); // temporary until unboxed closures land @@ -345,8 +353,8 @@ impl Process { unsafe { let mut pipes = [0; 2]; assert_eq!(libc::pipe(pipes.as_mut_ptr()), 0); - set_nonblocking(pipes[0], true).ok().unwrap(); - set_nonblocking(pipes[1], true).ok().unwrap(); + set_nonblocking(pipes[0], true); + set_nonblocking(pipes[1], true); WRITE_FD = pipes[1]; let mut old: c::sigaction = mem::zeroed(); @@ -362,7 +370,7 @@ impl Process { fn waitpid_helper(input: libc::c_int, messages: Receiver<Req>, (read_fd, old): (libc::c_int, c::sigaction)) { - set_nonblocking(input, true).ok().unwrap(); + set_nonblocking(input, true); let mut set: c::fd_set = unsafe { mem::zeroed() }; let mut tv: libc::timeval; let mut active = Vec::<(libc::pid_t, Sender<ProcessExit>, u64)>::new(); diff --git a/src/libstd/sys/unix/process2.rs b/src/libstd/sys/unix/process2.rs index 06fa5c4bba7..b7a1b002f55 100644 --- a/src/libstd/sys/unix/process2.rs +++ b/src/libstd/sys/unix/process2.rs @@ -141,7 +141,6 @@ impl Process { -> io::Result<Process> { use libc::funcs::posix88::unistd::{fork, dup2, close, chdir, execvp}; - use libc::funcs::bsd44::getdtablesize; mod rustrt { extern { @@ -154,6 +153,16 @@ impl Process { assert_eq!(ret, 0); } + #[cfg(all(target_os = "android", target_arch = "aarch64"))] + unsafe fn getdtablesize() -> c_int { + libc::sysconf(libc::consts::os::sysconf::_SC_OPEN_MAX) as c_int + } + + #[cfg(not(all(target_os = "android", target_arch = "aarch64")))] + unsafe fn getdtablesize() -> c_int { + libc::funcs::bsd44::getdtablesize() + } + let dirp = cfg.cwd.as_ref().map(|c| c.as_ptr()).unwrap_or(ptr::null()); with_envp(cfg.env.as_ref(), |envp: *const c_void| { diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs index c8f9d318482..b08f6ef9b90 100644 --- a/src/libstd/sys/unix/tcp.rs +++ b/src/libstd/sys/unix/tcp.rs @@ -67,9 +67,9 @@ impl TcpListener { -1 => Err(last_net_error()), _ => { let (reader, writer) = try!(unsafe { sys::os::pipe() }); - try!(set_nonblocking(reader.fd(), true)); - try!(set_nonblocking(writer.fd(), true)); - try!(set_nonblocking(self.fd(), true)); + set_nonblocking(reader.fd(), true); + set_nonblocking(writer.fd(), true); + set_nonblocking(self.fd(), true); Ok(TcpAcceptor { inner: Arc::new(AcceptorInner { listener: self, | 
