summaryrefslogtreecommitdiff
path: root/src/unistd.rs
diff options
context:
space:
mode:
authormusikid <musikid@outlook.com>2022-04-27 12:23:56 +0200
committerAlan Somers <asomers@gmail.com>2022-07-13 21:27:36 -0600
commit137a9abb666661d1546d471e61321a94ead2eca2 (patch)
tree7ce79bcd4233582a876480b8be0db1751d6b93ba /src/unistd.rs
parentfb65331a559ce3a51640ef6431562eea6cd39725 (diff)
downloadnix-137a9abb666661d1546d471e61321a94ead2eca2.zip
Add chflags
Diffstat (limited to 'src/unistd.rs')
-rw-r--r--src/unistd.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/unistd.rs b/src/unistd.rs
index e738349a..6dd0c164 100644
--- a/src/unistd.rs
+++ b/src/unistd.rs
@@ -6,6 +6,18 @@ use crate::errno::{self, Errno};
use crate::fcntl::{at_rawfd, AtFlags};
#[cfg(feature = "fs")]
use crate::fcntl::{fcntl, FcntlArg::F_SETFD, FdFlag, OFlag};
+#[cfg(all(
+ feature = "fs",
+ any(
+ target_os = "openbsd",
+ target_os = "netbsd",
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "macos",
+ target_os = "ios"
+ )
+))]
+use crate::sys::stat::FileFlag;
#[cfg(feature = "fs")]
use crate::sys::stat::Mode;
use crate::{Error, NixPath, Result};
@@ -3288,3 +3300,26 @@ pub fn getpeereid(fd: RawFd) -> Result<(Uid, Gid)> {
Errno::result(ret).map(|_| (Uid(uid), Gid(gid)))
}
}
+
+feature! {
+#![all(feature = "fs")]
+
+/// Set the file flags.
+///
+/// See also [chflags(2)](https://www.freebsd.org/cgi/man.cgi?query=chflags&sektion=2)
+#[cfg(any(
+ target_os = "openbsd",
+ target_os = "netbsd",
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "macos",
+ target_os = "ios"
+))]
+pub fn chflags<P: ?Sized + NixPath>(path: &P, flags: FileFlag) -> Result<()> {
+ let res = path.with_nix_path(|cstr| unsafe {
+ libc::chflags(cstr.as_ptr(), flags.bits())
+ })?;
+
+ Errno::result(res).map(drop)
+}
+}