diff --git a/CHANGELOG.md b/CHANGELOG.md index 31077e1ce9..3dfc253547 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#1084](https://github.com/nix-rust/nix/pull/1084)) - Add `posix_fadvise`. ([#1089](https://github.com/nix-rust/nix/pull/1089)) -- Add `rename`, `renameat`, and `AT_FDCWD`. +- Add `rename`, `renameat`, `unlinkat`, `AT_FDCWD`, and `AT_REMOVEDIR`. ([#1097](https://github.com/nix-rust/nix/pull/1097)) ### Changed diff --git a/src/fcntl.rs b/src/fcntl.rs index 79cbfe3d26..17f627a223 100644 --- a/src/fcntl.rs +++ b/src/fcntl.rs @@ -25,6 +25,7 @@ pub const AT_FDCWD: RawFd = libc::AT_FDCWD as RawFd; libc_bitflags!{ pub struct AtFlags: c_int { + AT_REMOVEDIR; AT_SYMLINK_NOFOLLOW; #[cfg(any(target_os = "android", target_os = "linux"))] AT_NO_AUTOMOUNT; diff --git a/src/unistd.rs b/src/unistd.rs index 96d8ace78c..dcc2db0311 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1144,6 +1144,15 @@ pub fn unlink(path: &P) -> Result<()> { Errno::result(res).map(drop) } +pub fn unlinkat(dirfd: RawFd, path: &P, flags: AtFlags) -> Result<()> { + let res = path.with_nix_path(|cstr| { + unsafe { + libc::unlinkat(dirfd, cstr.as_ptr(), flags.bits() as libc::c_int) + } + })?; + Errno::result(res).map(drop) +} + #[inline] pub fn chroot(path: &P) -> Result<()> { let res = path.with_nix_path(|cstr| {