diff options
| author | Florian Hartwig <florian.j.hartwig@gmail.com> | 2015-07-10 16:23:14 +0200 |
|---|---|---|
| committer | Florian Hartwig <florian.j.hartwig@gmail.com> | 2015-07-10 16:23:54 +0200 |
| commit | f200ad85bd8ead749dea217bdd65dfe130c4db18 (patch) | |
| tree | ee3ac84c268c577253ebc8a75a79ba6f13185cac /src/libstd/sys | |
| parent | cdcce3ba4491436e6603833cee19533003993117 (diff) | |
| download | rust-f200ad85bd8ead749dea217bdd65dfe130c4db18.tar.gz rust-f200ad85bd8ead749dea217bdd65dfe130c4db18.zip | |
Show file name and access mode in Debug instance for File on OS X
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/fs.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index 8113d0ea847..867cdcbab94 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -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 { @@ -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 |
