Skip to content

Commit 306bb59

Browse files
committed
fcntl add F_GETPATH support for apple/netbsd
1 parent 57663c0 commit 306bb59

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/fcntl.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,8 @@ pub enum FcntlArg<'a> {
489489
F_GETPIPE_SZ,
490490
#[cfg(any(target_os = "linux", target_os = "android"))]
491491
F_SETPIPE_SZ(c_int),
492+
#[cfg(any(target_os = "netbsd", target_os = "macos", target_os = "ios"))]
493+
F_GETPATH(Vec<u8>),
492494
// TODO: Rest of flags
493495
}
494496

@@ -549,6 +551,11 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
549551
F_GETPIPE_SZ => libc::fcntl(fd, libc::F_GETPIPE_SZ),
550552
#[cfg(any(target_os = "linux", target_os = "android"))]
551553
F_SETPIPE_SZ(size) => libc::fcntl(fd, libc::F_SETPIPE_SZ, size),
554+
#[cfg(any(target_os = "netbsd", target_os = "macos", target_os = "ios"))]
555+
F_GETPATH(path) => {
556+
path.resize(libc::PATH_MAX);
557+
libc::fcntl(fd, libc::F_GETPATH, path.as_ptr())
558+
},
552559
}
553560
};
554561

test/test_fcntl.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,3 +561,21 @@ mod test_posix_fallocate {
561561
}
562562
}
563563
}
564+
565+
#[test]
566+
#[cfg(any(target_os = "netbsd", target_os = "macos", target_os = "ios"))]
567+
mod test_apple_netbsd {
568+
use nix::fcntl::*;
569+
use tempfile::NamedTempFile;
570+
571+
#[test]
572+
fn test_path() {
573+
let mut tmp = NamedTempFile::new().unwrap();
574+
let fd = tmp.as_raw_fd();
575+
let mut path: Vec<u8> = Vec::new();
576+
let res = fcntl(fd, FcntlArg::F_GETPATH(path)).expect("get path failed");
577+
assert_eq!(
578+
path.len() > 0
579+
);
580+
}
581+
}

0 commit comments

Comments
 (0)