Skip to content

Commit

Permalink
Handle mode_t being u32 on Linux, u16 on BSD
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Heath <[email protected]>
  • Loading branch information
Jason Heath committed Sep 20, 2024
1 parent 30aa1c0 commit 15ad7b0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/core/src/util/posix_perm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,15 @@ fn chmod(path: &str, mode: u32) -> Result<c_int> {
/// Sets the umask of the running process to 0022 after its called
pub fn set_umask_0022() -> Result<u32> { umask(0o22 as mode_t) }

fn umask(mode: mode_t) -> Result<u32> { unsafe { Ok(libc::umask(mode)) } }
fn umask(mode: mode_t) -> Result<u32> {
unsafe {
// glibc and musl are u32, BSD heritage seems to use u16
#[cfg(not(target_os = "macos"))]
{ Ok(libc::umask(mode)) }
#[cfg(target_os = "macos")]
{ Ok(libc::umask(mode).into()) }
}
}

#[cfg(test)]
mod tests {
Expand Down

0 comments on commit 15ad7b0

Please sign in to comment.