From 137a9abb666661d1546d471e61321a94ead2eca2 Mon Sep 17 00:00:00 2001 From: musikid Date: Wed, 27 Apr 2022 12:23:56 +0200 Subject: Add chflags --- src/unistd.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/unistd.rs') 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(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) +} +} -- cgit v1.2.3