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

Closed
Gashrod1 wants to merge 1 commit from upstream-pr/4804 into main
Gashrod1 commented 2026-10-12 22:26:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gashrod1 on 2026-10-12T22:26:05Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4835705782 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4804). Originally posted by [Gashrod1](https://github.com/Gashrod1) on 2026-10-12T22:26:05Z. --- ### 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`](https://github.com/freebsd/freebsd-src/blob/main/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 <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-13 18:42:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T18:42:13Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152630184 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4804#issuecomment-6152630184). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T18:42:13Z. --- 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 commented 2026-10-13 18:52:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gashrod1 on 2026-10-13T18:52:35Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6152817986 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4804#issuecomment-6152817986). Originally posted by [Gashrod1](https://github.com/Gashrod1) on 2026-10-13T18:52:35Z. --- 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[bot] commented 2026-10-13 19:06:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T19:06:48Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153075276 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4804#issuecomment-6153075276). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T19:06:48Z. --- <!-- pr-overlap --> 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](https://github.com/boykopovar/AnyPS5/blob/cdea950b7e8b43fee556a48356120acaefd99f96/core/libs/prx/libc/src/Formatting.cpp#L543-L544) | | |
oneandonlydean commented 2026-10-14 02:38:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:38:01Z.


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.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159647148 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4804#issuecomment-6159647148). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:38:01Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4804
No description provided.