|
1 | 1 | use crate::errno::Errno; |
2 | 2 | use libc::{self, c_int, c_uint, size_t, ssize_t}; |
| 3 | +#[cfg(any( |
| 4 | + target_os = "netbsd", |
| 5 | + target_os = "macos", |
| 6 | + target_os = "ios", |
| 7 | + target_os = "dragonfly", |
| 8 | +))] |
| 9 | +use std::ffi::CStr; |
3 | 10 | use std::ffi::OsString; |
4 | 11 | #[cfg(not(target_os = "redox"))] |
5 | 12 | use std::os::raw; |
6 | 13 | use std::os::unix::ffi::OsStringExt; |
7 | 14 | use std::os::unix::io::RawFd; |
8 | 15 | // For splice and copy_file_range |
| 16 | +#[cfg(any( |
| 17 | + target_os = "netbsd", |
| 18 | + target_os = "macos", |
| 19 | + target_os = "ios", |
| 20 | + target_os = "dragonfly", |
| 21 | +))] |
| 22 | +use std::path::PathBuf; |
9 | 23 | #[cfg(any( |
10 | 24 | target_os = "android", |
11 | 25 | target_os = "freebsd", |
@@ -489,6 +503,8 @@ pub enum FcntlArg<'a> { |
489 | 503 | F_GETPIPE_SZ, |
490 | 504 | #[cfg(any(target_os = "linux", target_os = "android"))] |
491 | 505 | F_SETPIPE_SZ(c_int), |
| 506 | + #[cfg(any(target_os = "netbsd", target_os = "dragonfly", target_os = "macos", target_os = "ios"))] |
| 507 | + F_GETPATH(&'a mut PathBuf), |
492 | 508 | // TODO: Rest of flags |
493 | 509 | } |
494 | 510 |
|
@@ -549,6 +565,15 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> { |
549 | 565 | F_GETPIPE_SZ => libc::fcntl(fd, libc::F_GETPIPE_SZ), |
550 | 566 | #[cfg(any(target_os = "linux", target_os = "android"))] |
551 | 567 | F_SETPIPE_SZ(size) => libc::fcntl(fd, libc::F_SETPIPE_SZ, size), |
| 568 | + #[cfg(any(target_os = "dragonfly", target_os = "netbsd", target_os = "macos", target_os = "ios"))] |
| 569 | + F_GETPATH(path) => { |
| 570 | + let mut buffer = vec![0; libc::PATH_MAX as usize]; |
| 571 | + let res = libc::fcntl(fd, libc::F_GETPATH, buffer.as_mut_ptr()); |
| 572 | + let ok_res = Errno::result(res)?; |
| 573 | + let optr = CStr::from_bytes_until_nul(&buffer).unwrap(); |
| 574 | + *path = PathBuf::from(OsString::from(optr.to_str().unwrap())); |
| 575 | + return Ok(ok_res) |
| 576 | + }, |
552 | 577 | } |
553 | 578 | }; |
554 | 579 |
|
|
0 commit comments