Skip to content

Commit 489621e

Browse files
authored
Changed signature for openat function (#2139)
* Changed signature for openat function Signed-off-by: carlosb1 <[email protected]> * Fixed tests for openat to apply Options Signed-off-by: carlosb1 <[email protected]> * Updated changelog Signed-off-by: carlosb1 <[email protected]> * Fixed num PR Signed-off-by: carlosb1 <[email protected]> --------- Signed-off-by: carlosb1 <[email protected]>
1 parent c4ba877 commit 489621e

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ This project adheres to [Semantic Versioning](https://semver.org/).
2121
- `unistd::getpeereid`
2222

2323
([#2137](https://github.com/nix-rust/nix/pull/2137))
24+
25+
- Changed `openat()` and `Dir::openat()`, now take optional `dirfd`s
26+
([#2139](https://github.com/nix-rust/nix/pull/2139))
2427

2528
- `FdSet::{insert, remove, contains}` now take `BorrowedFd` arguments, and have
2629
relaxed lifetime requirements relative to 0.27.1.

src/dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl Dir {
4444

4545
/// Opens the given path as with `fcntl::openat`.
4646
pub fn openat<P: ?Sized + NixPath>(
47-
dirfd: RawFd,
47+
dirfd: Option<RawFd>,
4848
path: &P,
4949
oflag: OFlag,
5050
mode: sys::stat::Mode,

src/fcntl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ pub fn open<P: ?Sized + NixPath>(
220220
#[allow(clippy::useless_conversion)]
221221
#[cfg(not(target_os = "redox"))]
222222
pub fn openat<P: ?Sized + NixPath>(
223-
dirfd: RawFd,
223+
dirfd: Option<RawFd>,
224224
path: &P,
225225
oflag: OFlag,
226226
mode: Mode,
227227
) -> Result<RawFd> {
228228
let fd = path.with_nix_path(|cstr| unsafe {
229-
libc::openat(dirfd, cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint)
229+
libc::openat(at_rawfd(dirfd), cstr.as_ptr(), oflag.bits(), mode.bits() as c_uint)
230230
})?;
231231
Errno::result(fd)
232232
}

test/test_fcntl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn test_openat() {
4242
open(tmp.path().parent().unwrap(), OFlag::empty(), Mode::empty())
4343
.unwrap();
4444
let fd = openat(
45-
dirfd,
45+
Some(dirfd),
4646
tmp.path().file_name().unwrap(),
4747
OFlag::O_RDONLY,
4848
Mode::empty(),

0 commit comments

Comments
 (0)