Skip to content

Commit a0659eb

Browse files
committed
feat(display): add stdout write check in print_all_env_vars
Add a check to ensure stdout is writable before printing environment variables, preventing errors when stdout is closed. This uses a non-zero sentinel to trigger the check and mark write attempt.
1 parent 497ea56 commit a0659eb

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

src/uucore/src/lib/mods/display.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ impl OsWrite for Box<dyn OsWrite> {
129129
/// This function handles non-UTF-8 environment variable names and values correctly by using
130130
/// raw bytes on Unix systems.
131131
pub fn print_all_env_vars<T: fmt::Display>(line_ending: T) -> io::Result<()> {
132+
// Trigger stdout-closed check and mark "write attempted"; 1 is a non-zero sentinel.
132133
crate::check_stdout_write(1)?;
133134
let mut stdout = io::stdout().lock();
134135
for (name, value) in env::vars_os() {

0 commit comments

Comments
 (0)