Skip to content

Commit 4ebb41e

Browse files
committed
CHANGELOG entry
1 parent ed051c7 commit 4ebb41e

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
4949
- Added `Icmp` and `IcmpV6` to `SockProtocol`.
5050
(#[2103](https://github.com/nix-rust/nix/pull/2103))
5151

52+
- Added `F_GETPATH` FcntlFlags entry on Apple/NetBSD/DragonflyBSD for `::nix::fcntl`.
53+
([#2142](https://github.com/nix-rust/nix/pull/2142))
54+
5255
## [0.27.1] - 2023-08-28
5356

5457
### Fixed

src/fcntl.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
use crate::errno::Errno;
22
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;
310
use std::ffi::OsString;
411
#[cfg(not(target_os = "redox"))]
512
use std::os::raw;
@@ -561,13 +568,11 @@ 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));
570-
ok_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)
571576
},
572577
}
573578
};

test/test_fcntl.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -568,20 +568,19 @@ mod test_posix_fallocate {
568568
target_os = "macos",
569569
target_os = "ios"
570570
))]
571-
mod test_apple_netbsd {
571+
#[test]
572+
fn test_f_get_path() {
572573
use nix::fcntl::*;
573-
use std::os::unix::io::AsRawFd;
574-
use std::path::PathBuf;
575-
use tempfile::NamedTempFile;
576-
577-
#[test]
578-
fn test_path() {
579-
let tmp = NamedTempFile::new().unwrap();
580-
let fd = tmp.as_raw_fd();
581-
let mut path = PathBuf::new();
582-
let res =
583-
fcntl(fd, FcntlArg::F_GETPATH(&mut path)).expect("get path failed");
584-
assert_ne!(res, -1);
585-
assert_eq!(path, tmp.path());
586-
}
574+
use std::{os::unix::io::AsRawFd, path::PathBuf};
575+
576+
let tmp = NamedTempFile::new().unwrap();
577+
let fd = tmp.as_raw_fd();
578+
let mut path = PathBuf::new();
579+
let res =
580+
fcntl(fd, FcntlArg::F_GETPATH(&mut path)).expect("get path failed");
581+
assert_ne!(res, -1);
582+
assert_eq!(
583+
path.as_path().canonicalize().unwrap(),
584+
tmp.path().canonicalize().unwrap()
585+
);
587586
}

0 commit comments

Comments
 (0)