summaryrefslogtreecommitdiff
path: root/src/fcntl.rs
diff options
context:
space:
mode:
authorScott Lamb <slamb@slamb.org>2019-07-11 16:31:56 -0700
committerScott Lamb <slamb@slamb.org>2019-07-17 14:13:21 -0700
commit6454a06c341de7f1c92f97222a6c37572176ee9b (patch)
tree88f43b27af20ffe1fb270d0266c626f19cc39989 /src/fcntl.rs
parent500036a206188dc8f57bf95a7c61616db417038e (diff)
downloadnix-6454a06c341de7f1c92f97222a6c37572176ee9b.zip
Add renameat
renameat is (somewhat oddly, imho) in stdio.h. I put it in nix::fcntl because there's no nix::stdio and all its friends (including the AT_* constants) are in nix::fcntl.
Diffstat (limited to 'src/fcntl.rs')
-rw-r--r--src/fcntl.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/fcntl.rs b/src/fcntl.rs
index d99c2c1a..be6ee0f7 100644
--- a/src/fcntl.rs
+++ b/src/fcntl.rs
@@ -165,6 +165,18 @@ pub fn openat<P: ?Sized + NixPath>(dirfd: RawFd, path: &P, oflag: OFlag, mode: M
Errno::result(fd)
}
+pub fn renameat<P1: ?Sized + NixPath, P2: ?Sized + NixPath>(old_dirfd: Option<RawFd>, old_path: &P1,
+ new_dirfd: Option<RawFd>, new_path: &P2)
+ -> Result<()> {
+ let res = old_path.with_nix_path(|old_cstr| {
+ new_path.with_nix_path(|new_cstr| unsafe {
+ libc::renameat(at_rawfd(old_dirfd), old_cstr.as_ptr(),
+ at_rawfd(new_dirfd), new_cstr.as_ptr())
+ })
+ })??;
+ Errno::result(res).map(drop)
+}
+
fn wrap_readlink_result(buffer: &mut[u8], res: ssize_t) -> Result<&OsStr> {
match Errno::result(res) {
Err(err) => Err(err),