mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
uucore::mode: Add notes about umask and platform support
This commit is contained in:
parent
8cfe0290cd
commit
cc652c7fe9
3 changed files with 9 additions and 2 deletions
|
@ -10,7 +10,7 @@ pub mod fsext;
|
||||||
pub mod ringbuffer;
|
pub mod ringbuffer;
|
||||||
|
|
||||||
// * (platform-specific) feature-gated modules
|
// * (platform-specific) feature-gated modules
|
||||||
// ** non-windows
|
// ** non-windows (i.e. Unix + Fuchsia)
|
||||||
#[cfg(all(not(windows), feature = "mode"))]
|
#[cfg(all(not(windows), feature = "mode"))]
|
||||||
pub mod mode;
|
pub mod mode;
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,13 @@ pub fn parse_mode(mode: &str) -> Result<mode_t, String> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_umask() -> u32 {
|
pub fn get_umask() -> u32 {
|
||||||
|
// There's no portable way to read the umask without changing it.
|
||||||
|
// We have to replace it and then quickly set it back, hopefully before
|
||||||
|
// some other thread is affected.
|
||||||
|
// On modern Linux kernels the current umask could instead be read
|
||||||
|
// from /proc/self/status. But that's a lot of work.
|
||||||
|
// SAFETY: umask always succeeds and doesn't operate on memory. Races are
|
||||||
|
// possible but it can't violate Rust's guarantees.
|
||||||
let mask = unsafe { umask(0) };
|
let mask = unsafe { umask(0) };
|
||||||
unsafe { umask(mask) };
|
unsafe { umask(mask) };
|
||||||
mask as u32
|
mask as u32
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub use crate::features::fsext;
|
||||||
pub use crate::features::ringbuffer;
|
pub use crate::features::ringbuffer;
|
||||||
|
|
||||||
// * (platform-specific) feature-gated modules
|
// * (platform-specific) feature-gated modules
|
||||||
// ** non-windows
|
// ** non-windows (i.e. Unix + Fuchsia)
|
||||||
#[cfg(all(not(windows), feature = "mode"))]
|
#[cfg(all(not(windows), feature = "mode"))]
|
||||||
pub use crate::features::mode;
|
pub use crate::features::mode;
|
||||||
// ** unix-only
|
// ** unix-only
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue