diff --git a/Cargo.toml b/Cargo.toml
index 29c631ece6..e4f42373de 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -22,7 +22,7 @@ preadv_pwritev = []
signalfd = []
[dependencies]
-libc = { git = "https://github.com/rust-lang/libc" }
+libc = { git = "https://github.com/Mic92/libc", branch = "master" }
bitflags = "0.7"
cfg-if = "0.1.0"
void = "1.0.2"
diff --git a/src/dirent.rs b/src/dirent.rs
new file mode 100644
index 0000000000..98c97eebf1
--- /dev/null
+++ b/src/dirent.rs
@@ -0,0 +1,50 @@
+use {Result, Error, Errno, NixPath};
+use libc::{self, DIR};
+use std::os::unix::io::RawFd;
+use errno;
+
+pub struct Dir {
+ handle: *mut DIR,
+}
+
+impl Drop for Dir {
+ fn drop(&mut self) {
+ unsafe { libc::closedir(self.handle) };
+ }
+}
+
+pub fn fdopendir(fd: RawFd) -> Result
{
+ let dirp = unsafe { libc::fdopendir(fd) };
+ if dirp.is_null() {
+ Err(Error::last().into())
+ } else {
+ Ok(Dir { handle: dirp })
+ }
+}
+
+pub fn opendir(name: &P) -> Result {
+ let dirp = try!(name.with_nix_path(|cstr| {
+ unsafe { libc::opendir(cstr.as_ptr()) }
+ }));
+ if dirp.is_null() {
+ Err(Error::last().into())
+ } else {
+ Ok(Dir { handle: dirp })
+ }
+}
+
+pub fn readdir<'a>(dir: &'a mut Dir) -> Result