Skip to content

Conversation

@ChrisX101010
Copy link

Fixes #10239

let write_result = match name {
Ok(name) => stdout.write_all_os(name.as_os_str()),
Ok(name) => {
stdout.write_all_os(name.as_os_str())?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(/bin/tty >&- 2>/dev/null); echo $?

This command shows what happens when theres an error in writing to stdout, the error code that GNU is expecting is 3, but by adding that ? it will make it handled and return a 1. You can get around this by doing:

Ok(name) => stdout
    .write_all_os(name.as_os_str())
    .and_then(|_| writeln!(stdout)),

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

target/debug/tty > /dev/full silently returns 3. But GNU have tty: write error: No space left on device.

@ChrisX101010
Copy link
Author

@ChrisDryden can you check now, sir? thank you!

@oech3
Copy link
Contributor

oech3 commented Jan 15, 2026

Would you add test to check newline (and exit code of >/dev/full if possible ) to
https://github.com/uutils/coreutils/blob/main/tests/by-util/test_tty.rs ? Thankyou.

@github-actions
Copy link

GNU testsuite comparison:

Note: The gnu test tests/basenc/bounded-memory is now being skipped but was previously passing.

@ChrisX101010
Copy link
Author

@oech3 Hi, sir! Please check now and let me know. Thank you! Have a nice weekend. :)

if write_result.is_err() || stdout.flush().is_err() {

if let Err(e) = write_result {
eprintln!("tty: write error: {}", e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you change this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisDryden I removed it because I thought it was redundant (flush was already called in line 37), but I've now restored it to match the original pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we can extract it from OS provided err message.
(Also please cargo fmt)

@ChrisX101010
Copy link
Author

I changed it to print the error message before exiting (as requested in the previous feedback about matching GNU tty's 'write error' output).

However, I notice I removed the separate stdout.flush() check. The flush is still being called in the Ok(name) branch (line 37), but I can restore the separate check if you prefer. Should I keep both checks separately?

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 17, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 27.39%

Comparing ChrisX101010:fix-tty-missing-newline (2c92d38) with main (a1545ef)

Summary

⚡ 1 improved benchmark
❌ 7 regressed benchmarks
✅ 274 untouched benchmarks
⏩ 38 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory sort_numeric[500000] 75.5 MB 79.2 MB -4.66%
Memory sort_ascii_only[500000] 22.2 MB 28.3 MB -21.77%
Memory sort_unique_locale[500000] 33.6 MB 39.8 MB -15.51%
Memory sort_mixed_data[500000] 22.9 MB 27.1 MB -15.71%
Memory sort_key_field[500000] 47.8 MB 51.8 MB -7.62%
Memory sort_accented_data[500000] 22.1 MB 28.3 MB -21.79%
Memory sort_long_line[160000] 712.6 KB 981.4 KB -27.39%
Memory dd_copy_default 130.8 KB 126.9 KB +3.08%

Footnotes

  1. 38 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tty: missing newline

3 participants