Skip to content

Commit 0bef880

Browse files
committed
readlink: introduce IS_POSIXLY_CORRECT static
1 parent e92473f commit 0bef880

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/uu/readlink/src/readlink.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::ffi::OsString;
1111
use std::fs;
1212
use std::io::{Write, stdout};
1313
use std::path::{Path, PathBuf};
14+
use std::sync::LazyLock;
1415
use uucore::display::Quotable;
1516
use uucore::error::{FromIo, UResult, UUsageError};
1617
use uucore::fs::{MissingHandling, ResolveMode, canonicalize};
@@ -36,7 +37,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
3637

3738
let mut no_trailing_delimiter = matches.get_flag(OPT_NO_NEWLINE);
3839
let use_zero = matches.get_flag(OPT_ZERO);
39-
let verbose = matches.get_flag(OPT_VERBOSE) || env::var("POSIXLY_CORRECT").is_ok();
40+
let verbose = matches.get_flag(OPT_VERBOSE) || *IS_POSIXLY_CORRECT;
4041

4142
// GNU readlink -f/-e/-m follows symlinks first and then applies `..` (physical resolution).
4243
// ResolveMode::Logical collapses `..` before following links, which yields the opposite order,
@@ -192,3 +193,6 @@ fn show(path: &Path, line_ending: Option<LineEnding>) -> std::io::Result<()> {
192193
}
193194
stdout().flush()
194195
}
196+
197+
static IS_POSIXLY_CORRECT: LazyLock<bool> =
198+
LazyLock::new(|| env::var_os("POSIXLY_CORRECT").is_some());

0 commit comments

Comments
 (0)