Skip to content

Commit 6f6129d

Browse files
committed
CHANGELOG entry
1 parent 18aa300 commit 6f6129d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
6767
([#2097](https://github.com/nix-rust/nix/pull/2097))
6868
- Add the ability to set `kevent_flags` on `SigEvent`.
6969
([#1731](https://github.com/nix-rust/nix/pull/1731))
70+
- Added `F_GETPATH` FcntlFlags entry on Apple/NetBSD/DragonflyBSD for `::nix::fcntl`.
71+
([#2142](https://github.com/nix-rust/nix/pull/2142))
7072

7173
### Changed
7274

src/fcntl.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
use crate::errno::Errno;
22
use libc::{self, c_char, c_int, c_uint, size_t, ssize_t};
33
use std::ffi::OsString;
4+
#[cfg(any(
5+
target_os = "netbsd",
6+
target_os = "macos",
7+
target_os = "ios",
8+
target_os = "dragonfly",
9+
))]
10+
use std::ffi::CStr;
411
#[cfg(not(target_os = "redox"))]
512
use std::os::raw;
613
use std::os::unix::ffi::OsStringExt;
@@ -561,12 +568,10 @@ pub fn fcntl(fd: RawFd, arg: FcntlArg) -> Result<c_int> {
561568
#[cfg(any(target_os = "dragonfly", target_os = "netbsd", target_os = "macos", target_os = "ios"))]
562569
F_GETPATH(path) => {
563570
let mut buffer = vec![0; libc::PATH_MAX as usize];
564-
let res = libc::fcntl(fd, libc::F_GETPATH, buffer.as_ptr());
571+
let res = libc::fcntl(fd, libc::F_GETPATH, buffer.as_mut_ptr());
565572
let ok_res = Errno::result(res)?;
566-
let len = buffer.iter().position(|b| *b == 0).unwrap();
567-
buffer.truncate(len as usize);
568-
buffer.shrink_to_fit();
569-
*path = PathBuf::from(OsString::from_vec(buffer));
573+
let optr = CStr::from_bytes_until_nul(&mut buffer).unwrap();
574+
*path = PathBuf::from(OsString::from(optr.to_str().unwrap()));
570575
ok_res
571576
},
572577
}

test/test_fcntl.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,10 @@ mod test_apple_netbsd {
582582
let res =
583583
fcntl(fd, FcntlArg::F_GETPATH(&mut path)).expect("get path failed");
584584
assert_ne!(res, -1);
585-
assert_eq!(path, tmp.path());
585+
// We purposely check the canonical names for equality checks.
586+
// The left operand tend to have `/private/var` whereas the right does not contains
587+
// the `/private` part even tough in practice they lead to the same file, indeed
588+
// `/var` is a symlink to `/private/var`.
589+
assert_eq!(path.as_path().canonicalize().unwrap(), tmp.path().canonicalize().unwrap());
586590
}
587591
}

0 commit comments

Comments
 (0)