Skip to content

fix(libc): return a newline from puts like FreeBSD - #4804

Closed
Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:fix/libc-puts-return-newline
Closed

Gashrod1 wants to merge 1 commit into
boykopovar:mainfrom
Gashrod1:fix/libc-puts-return-newline

Conversation

@Gashrod1

@Gashrod1 Gashrod1 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

What

puts_nid_postfix returned the host's puts result: strlen(s) + 1 on glibc and 0 on the Windows runtime. FreeBSD returns '\n' on success (lib/libc/stdio/puts.c: retval = __sfvwrite(stdout, &uio) ? EOF : '\n';). It now returns '\n', and EOF on failure as before.

file_streams checks puts with a non-empty and an empty string. It fails on main and passes with the change.

Tested

Linux (Arch, GCC), Release, BUILD_TESTING=ON, based on main ee4962190: file_streams aborts on main and passes with the change (3 runs); full build and full ctest pass. Windows (WinLibs MinGW-w64 GCC 15.2.0 r7, NVIDIA RTX 5060), Release, BUILD_TESTING=ON: full build and full ctest pass (1018 tests, the same 7 skipped as on main). No title or homebrew run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@MarcZX10

Copy link
Copy Markdown
Contributor

I opened #5394 to carry the Windows line-buffering fix from #5391. It touches puts_nid_postfix to flush the newline; I listed #4804 as a dependency so your puts return-value change can land first, then I can rebase and resolve the shared line. If you prefer a different merge order, please say so.

@Gashrod1

Copy link
Copy Markdown
Contributor Author

Thanks for the heads-up, that merge order works for me. After #4804, puts returns '\n' on success instead of the host's non-negative value. Your result >= 0 check still holds, so the rebase should only need to keep both changes on that line.

One related point: #5394 also touches fputs_nid_postfix, and #4803 changes its return value to the written length (capped at INT_MAX), as FreeBSD's fputs does. The new line-buffered branch returns 0 on success, so whichever lands second should return the length there too, e.g. static_cast<int>(std::min<std::size_t>(length, INT_MAX)). I'm happy to rebase #4803 on top of yours if it goes in first.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5632 core/libs/prx/libc/src/Formatting.cpp L543-544

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants