Skip to content

Commit 8809cd0

Browse files
committed
uucore: readlink: introduce IS_POSIXLY_CORRECT static
1 parent 0bef880 commit 8809cd0

2 files changed

Lines changed: 6 additions & 13 deletions

File tree

src/uu/df/src/blocks.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,4 @@ mod tests {
367367
assert_eq!(format!("{}", BlockSize::Bytes(1000 * 1024)), "1.1MB");
368368
assert_eq!(format!("{}", BlockSize::Bytes(1_000_000_000_000)), "1.0TB");
369369
}
370-
371-
#[test]
372-
fn test_default_block_size() {
373-
assert_eq!(BlockSize::Bytes(1024), BlockSize::default());
374-
unsafe { env::set_var("POSIXLY_CORRECT", "1") };
375-
assert_eq!(BlockSize::Bytes(512), BlockSize::default());
376-
unsafe { env::remove_var("POSIXLY_CORRECT") };
377-
}
378370
}

src/uucore/src/lib/features/parser/parse_block_size.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
//! for resolving block sizes from environment variables and defaults.
1010
//! This module centralizes that logic.
1111
12+
use std::sync::LazyLock;
13+
1214
use super::parse_size::parse_size_non_zero_u64;
1315

1416
/// Result of looking up a block size from environment variables.
@@ -66,13 +68,12 @@ pub fn block_size_from_env(vars: &[&str]) -> BlockSizeEnv {
6668
///
6769
/// Returns 512 if `POSIXLY_CORRECT` is set, 1024 otherwise.
6870
pub fn default_block_size() -> u64 {
69-
if std::env::var("POSIXLY_CORRECT").is_ok() {
70-
512
71-
} else {
72-
1024
73-
}
71+
if *IS_POSIXLY_CORRECT { 512 } else { 1024 }
7472
}
7573

74+
static IS_POSIXLY_CORRECT: LazyLock<bool> =
75+
LazyLock::new(|| std::env::var_os("POSIXLY_CORRECT").is_some());
76+
7677
#[cfg(test)]
7778
mod tests {
7879
use super::*;

0 commit comments

Comments
 (0)