From e0100781277b2ca6e69975405f95195e28b19797 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 21 Feb 2017 15:07:03 -0800 Subject: [PATCH 1/2] Make readdir available on all unix targets The readdir_r call has problems, and we'll probably want to move to readdir on many, if not most, unix targets. This patch makes readdir available in unix, rather than just solaris as before. See https://github.com/rust-lang/rust/issues/40021 --- src/unix/mod.rs | 3 +++ src/unix/solaris/mod.rs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 427553d13ebf3..224061c822a99 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -350,6 +350,9 @@ extern { link_name = "opendir$INODE64$UNIX2003")] #[cfg_attr(target_os = "netbsd", link_name = "__opendir30")] pub fn opendir(dirname: *const c_char) -> *mut ::DIR; + #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] + #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] + pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent, diff --git a/src/unix/solaris/mod.rs b/src/unix/solaris/mod.rs index 5a15f81286ddb..1247917bc27d9 100644 --- a/src/unix/solaris/mod.rs +++ b/src/unix/solaris/mod.rs @@ -1017,7 +1017,6 @@ extern { buflen: ::c_int) -> *const passwd; pub fn setpwent(); pub fn getpwent() -> *mut passwd; - pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; pub fn fdatasync(fd: ::c_int) -> ::c_int; pub fn nl_langinfo_l(item: ::nl_item, locale: ::locale_t) -> *mut ::c_char; pub fn duplocale(base: ::locale_t) -> ::locale_t; From 02990f2fd2801908e0f8e2022270b504c4359829 Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Tue, 21 Feb 2017 19:13:16 -0800 Subject: [PATCH 2/2] Change return type of readdir to *mut ::dirent Apparently a lot of libc's don't put "const" on the return type for readdir, which causes type mismatch. --- src/unix/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 224061c822a99..4ff759c0ba81d 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -352,7 +352,7 @@ extern { pub fn opendir(dirname: *const c_char) -> *mut ::DIR; #[cfg_attr(target_os = "macos", link_name = "readdir$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir30")] - pub fn readdir(dirp: *mut ::DIR) -> *const ::dirent; + pub fn readdir(dirp: *mut ::DIR) -> *mut ::dirent; #[cfg_attr(target_os = "macos", link_name = "readdir_r$INODE64")] #[cfg_attr(target_os = "netbsd", link_name = "__readdir_r30")] pub fn readdir_r(dirp: *mut ::DIR, entry: *mut ::dirent,