summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authorNate Avers <nathan.avers@alumni.case.edu>2020-06-07 13:57:29 -0400
committerNate Avers <nathan.avers@alumni.case.edu>2020-06-12 11:44:04 -0400
commitba3f3e515a2c9ba7321e93c39c8b037c372d816b (patch)
tree7232a3c11140a7593b04f99aa093e43816f95092 /src/unistd.rs
parent93af76f1bdb2cbbe301a48f6a30c9b0ea00a839d (diff)
downloadnix-ba3f3e515a2c9ba7321e93c39c8b037c372d816b.zip
Add fchown(2) wrapper.
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index 8ff71e05..c09e4019 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -651,6 +651,20 @@ pub fn chown<P: ?Sized + NixPath>(path: &P, owner: Option<Uid>, group: Option<Gi
Errno::result(res).map(drop)
}
+/// Change the ownership of the file referred to by the open file descriptor `fd` to be owned by
+/// the specified `owner` (user) and `group` (see
+/// [fchown(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/fchown.html)).
+///
+/// The owner/group for the provided file will not be modified if `None` is
+/// provided for that argument. Ownership change will be attempted for the path
+/// only if `Some` owner/group is provided.
+#[inline]
+pub fn fchown(fd: RawFd, owner: Option<Uid>, group: Option<Gid>) -> Result<()> {
+ let (uid, gid) = chown_raw_ids(owner, group);
+ let res = unsafe { libc::fchown(fd, uid, gid) };
+ Errno::result(res).map(drop)
+}
+
/// Flags for `fchownat` function.
#[derive(Clone, Copy, Debug)]
pub enum FchownatFlags {