summaryrefslogtreecommitdiff
path: root/src/dir.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/dir.rs')
-rw-r--r--src/dir.rs23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/dir.rs b/src/dir.rs
index 42731a4e..9648fd43 100644
--- a/src/dir.rs
+++ b/src/dir.rs
@@ -1,17 +1,25 @@
+#[cfg(not(target_os = "redox"))]
use {Error, NixPath, Result};
+#[cfg(not(target_os = "redox"))]
use errno::Errno;
+#[cfg(not(target_os = "redox"))]
use fcntl::{self, OFlag};
use libc;
-use std::os::unix::io::{IntoRawFd, RawFd};
#[cfg(not(target_os = "redox"))]
-use std::os::unix::io::AsRawFd;
-use std::{ffi, ptr};
+use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd};
+#[cfg(not(target_os = "redox"))]
+use std::ptr;
+use std::ffi;
+#[cfg(not(target_os = "redox"))]
use sys;
#[cfg(target_os = "linux")]
use libc::{dirent64 as dirent, readdir64_r as readdir_r};
-#[cfg(not(target_os = "linux"))]
+#[cfg(target_os = "redox")]
+use libc::dirent;
+
+#[cfg(not(any(target_os = "linux", target_os = "redox")))]
use libc::{dirent, readdir_r};
/// An open directory.
@@ -28,10 +36,12 @@ use libc::{dirent, readdir_r};
/// * returns entries' names as a `CStr` (no allocation or conversion beyond whatever libc
/// does).
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
+#[cfg(not(target_os = "redox"))]
pub struct Dir(
ptr::NonNull<libc::DIR>
);
+#[cfg(not(target_os = "redox"))]
impl Dir {
/// Opens the given path as with `fcntl::open`.
pub fn open<P: ?Sized + NixPath>(path: &P, oflag: OFlag,
@@ -77,6 +87,7 @@ impl Dir {
// call `readdir` simultaneously from multiple threads.
//
// `Dir` is safe to pass from one thread to another, as it's not reference-counted.
+#[cfg(not(target_os = "redox"))]
unsafe impl Send for Dir {}
#[cfg(not(target_os = "redox"))]
@@ -86,6 +97,7 @@ impl AsRawFd for Dir {
}
}
+#[cfg(not(target_os = "redox"))]
impl Drop for Dir {
fn drop(&mut self) {
unsafe { libc::closedir(self.0.as_ptr()) };
@@ -93,8 +105,10 @@ impl Drop for Dir {
}
#[derive(Debug, Eq, Hash, PartialEq)]
+#[cfg(not(target_os = "redox"))]
pub struct Iter<'d>(&'d mut Dir);
+#[cfg(not(target_os = "redox"))]
impl<'d> Iterator for Iter<'d> {
type Item = Result<Entry>;
@@ -121,6 +135,7 @@ impl<'d> Iterator for Iter<'d> {
}
}
+#[cfg(not(target_os = "redox"))]
impl<'d> Drop for Iter<'d> {
fn drop(&mut self) {
unsafe { libc::rewinddir((self.0).0.as_ptr()) }