use sync::Arc;
use sys::fd::FileDesc;
use sys::platform::raw;
-use sys::{c, cvt, cvt_r};
+use sys::{cvt, cvt_r};
use sys_common::{AsInner, FromInner};
use vec::Vec;
unsafe impl Sync for Dir {}
pub struct DirEntry {
- buf: Vec<u8>, // actually *mut libc::dirent_t
+ buf: Vec<u8>, // actually *mut libc::dirent
root: Arc<PathBuf>,
}
let mut buf: Vec<u8> = Vec::with_capacity(unsafe {
rust_dirent_t_size() as usize
});
- let ptr = buf.as_mut_ptr() as *mut libc::dirent_t;
+ let ptr = buf.as_mut_ptr() as *mut libc::dirent;
let mut entry_ptr = ptr::null_mut();
loop {
pub fn file_type(&self) -> io::Result<FileType> {
extern {
- fn rust_dir_get_mode(ptr: *mut libc::dirent_t) -> c_int;
+ fn rust_dir_get_mode(ptr: *mut libc::dirent) -> c_int;
}
unsafe {
match rust_dir_get_mode(self.dirent()) {
pub fn ino(&self) -> raw::ino_t {
extern {
- fn rust_dir_get_ino(ptr: *mut libc::dirent_t) -> raw::ino_t;
+ fn rust_dir_get_ino(ptr: *mut libc::dirent) -> raw::ino_t;
}
unsafe { rust_dir_get_ino(self.dirent()) }
}
fn name_bytes(&self) -> &[u8] {
extern {
- fn rust_list_dir_val(ptr: *mut libc::dirent_t) -> *const c_char;
+ fn rust_list_dir_val(ptr: *mut libc::dirent) -> *const c_char;
}
unsafe {
CStr::from_ptr(rust_list_dir_val(self.dirent())).to_bytes()
}
}
- fn dirent(&self) -> *mut libc::dirent_t {
+ fn dirent(&self) -> *mut libc::dirent {
self.buf.as_ptr() as *mut _
}
}
(false, false) => libc::O_RDONLY,
};
let fd = try!(cvt_r(|| unsafe {
- libc::open(path.as_ptr(), flags, opts.mode)
+ libc::open(path.as_ptr(), flags, opts.mode as c_int)
}));
let fd = FileDesc::new(fd);
// Even though we open with the O_CLOEXEC flag, still set CLOEXEC here,
}
fn cstr(path: &Path) -> io::Result<CString> {
- path.as_os_str().to_cstring().ok_or(
- io::Error::new(io::ErrorKind::InvalidInput, "path contained a null"))
+ Ok(try!(CString::new(path.as_os_str().as_bytes())))
}
impl FromInner<c_int> for File {
let path = try!(CString::new(p.as_os_str().as_bytes()));
let buf;
unsafe {
- let r = c::realpath(path.as_ptr(), ptr::null_mut());
+ let r = libc::realpath(path.as_ptr(), ptr::null_mut());
if r.is_null() {
return Err(io::Error::last_os_error())
}