Skip to content

Show file name and access mode in Debug instance for File on OS X #26941

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/liblibc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4978,6 +4978,8 @@ pub mod consts {
pub const F_GETFL : c_int = 3;
pub const F_SETFL : c_int = 4;

pub const O_ACCMODE : c_int = 3;

pub const SIGTRAP : c_int = 5;
pub const SIG_IGN: size_t = 1;

Expand Down Expand Up @@ -5130,6 +5132,7 @@ pub mod consts {
pub const O_DSYNC : c_int = 4194304;
pub const O_SYNC : c_int = 128;
pub const O_NONBLOCK : c_int = 4;
pub const F_GETPATH : c_int = 50;
pub const F_FULLFSYNC : c_int = 51;

pub const MAP_COPY : c_int = 0x0002;
Expand All @@ -5151,6 +5154,8 @@ pub mod consts {
pub const SO_DONTTRUNC: c_int = 0x2000;
pub const SO_WANTMORE: c_int = 0x4000;
pub const SO_WANTOOBFLAG: c_int = 0x8000;

pub const PATH_MAX: c_int = 1024;
}
pub mod sysconf {
use types::os::arch::c95::c_int;
Expand Down
18 changes: 15 additions & 3 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,25 @@ impl fmt::Debug for File {
readlink(&p).ok()
}

#[cfg(not(target_os = "linux"))]
#[cfg(target_os = "macos")]
fn get_path(fd: c_int) -> Option<PathBuf> {
let mut buf = vec![0;libc::PATH_MAX as usize];
let n = unsafe { libc::fcntl(fd, libc::F_GETPATH, buf.as_ptr()) };
if n == -1 {
return None;
}
let l = buf.iter().position(|&c| c == 0).unwrap();
buf.truncate(l as usize);
Some(PathBuf::from(OsString::from_vec(buf)))
}

#[cfg(not(any(target_os = "linux", target_os = "macos")))]
fn get_path(_fd: c_int) -> Option<PathBuf> {
// FIXME(#24570): implement this for other Unix platforms
None
}

#[cfg(target_os = "linux")]
#[cfg(any(target_os = "linux", target_os = "macos"))]
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
if mode == -1 {
Expand All @@ -390,7 +402,7 @@ impl fmt::Debug for File {
}
}

#[cfg(not(target_os = "linux"))]
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
fn get_mode(_fd: c_int) -> Option<(bool, bool)> {
// FIXME(#24570): implement this for other Unix platforms
None
Expand Down