Skip to content

Commit

Permalink
iOS/tvOS/watchOS/visionOS: Improve File Debug impl
Browse files Browse the repository at this point in the history
This uses `libc::fcntl`, which, while not explicitly marked as available
in the headers, is already used by `File::sync_all` and `File::sync_data`
on these platforms, so should be fine to use here as well.
  • Loading branch information
madsmtm committed May 6, 2024
1 parent 28622c9 commit 2bd4dec
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions library/std/src/sys/pal/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1493,7 +1493,7 @@ impl fmt::Debug for File {
readlink(&p).ok()
}

#[cfg(target_os = "macos")]
#[cfg(target_vendor = "apple")]
fn get_path(fd: c_int) -> Option<PathBuf> {
// FIXME: The use of PATH_MAX is generally not encouraged, but it
// is inevitable in this case because macOS defines `fcntl` with
Expand Down Expand Up @@ -1538,12 +1538,12 @@ impl fmt::Debug for File {

#[cfg(not(any(
target_os = "linux",
target_os = "macos",
target_os = "vxworks",
all(target_os = "freebsd", target_arch = "x86_64"),
target_os = "netbsd",
target_os = "illumos",
target_os = "solaris"
target_os = "solaris",
target_vendor = "apple",
)))]
fn get_path(_fd: c_int) -> Option<PathBuf> {
// FIXME(#24570): implement this for other Unix platforms
Expand All @@ -1552,12 +1552,12 @@ impl fmt::Debug for File {

#[cfg(any(
target_os = "linux",
target_os = "macos",
target_os = "freebsd",
target_os = "hurd",
target_os = "netbsd",
target_os = "openbsd",
target_os = "vxworks"
target_os = "vxworks",
target_vendor = "apple",
))]
fn get_mode(fd: c_int) -> Option<(bool, bool)> {
let mode = unsafe { libc::fcntl(fd, libc::F_GETFL) };
Expand All @@ -1574,12 +1574,12 @@ impl fmt::Debug for File {

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

0 comments on commit 2bd4dec

Please sign in to comment.