Skip to content

Commit

Permalink
Add lchmod for bsd
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowone committed Apr 19, 2024
1 parent 1c2cad8 commit 98bb5a3
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/sys/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,28 @@ pub fn fchmodat<P: ?Sized + NixPath>(
Errno::result(res).map(drop)
}

/// Change the file permission bits of the file specified by a file descriptor.
///
/// # References
///
/// [lchmod(3)](https://man.freebsd.org/cgi/man.cgi?query=lchmod&sektion=2).
#[cfg(any(
target_os = "macos",
freebsdlike,
target_os = "openbsd",
))]
pub fn lchmod<P: ?Sized + NixPath>(path: P, mode: Mode) -> Result<()> {
extern "C" {
fn lchmod(path: *const libc::c_char, mode: libc::mode_t) -> libc::c_int;
}

let res = path.with_nix_path(|cstr| unsafe {
lchmod(cstr.as_ptr(), mode.bits() as mode_t)
})?;

Errno::result(res).map(drop)
}

/// Change the access and modification times of a file.
///
/// `utimes(path, times)` is identical to
Expand Down

0 comments on commit 98bb5a3

Please sign in to comment.