fix(libc): return fclose failures to callers #3926

Merged
MarcZX10 merged 1 commit from upstream-pr/3926 into main 2026-10-12 12:24:44 +00:00
MarcZX10 commented 2026-10-11 19:13:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T19:13:24Z.


What

fclose currently discards the host fclose result and always returns success. FileStream::Close now returns that result after invalidating the guest stream state, and fclose_nid_postfix propagates it. This lets callers observe buffered-write failures as EOF instead of false success.

Adds a Linux regression using /dev/full: buffer a write, then require fclose to report EOF when the flush fails.

Tested

  • Linux GCC 12.2, Release, Ninja: built guest_fiopen_tests; guest_fiopen passed (1/1), including the /dev/full close-failure case.
  • tools/check_conventions.py --base upstream/main and git diff --check upstream/main...HEAD passed.

Checklist

  • Based on current main; checked for duplicate open PRs
  • One topic per PR
  • No investigation notes added
  • Generic behavior
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4821613648 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3926). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-11T19:13:24Z. --- ### What `fclose` currently discards the host `fclose` result and always returns success. `FileStream::Close` now returns that result after invalidating the guest stream state, and `fclose_nid_postfix` propagates it. This lets callers observe buffered-write failures as `EOF` instead of false success. Adds a Linux regression using `/dev/full`: buffer a write, then require `fclose` to report `EOF` when the flush fails. ### Tested - Linux GCC 12.2, Release, Ninja: built `guest_fiopen_tests`; `guest_fiopen` passed (1/1), including the `/dev/full` close-failure case. - `tools/check_conventions.py --base upstream/main` and `git diff --check upstream/main...HEAD` passed. ### Checklist - [x] Based on current main; checked for duplicate open PRs - [x] One topic per PR - [x] No investigation notes added - [x] Generic behavior - [x] Depends on: none - [x] AI-assisted: yes
Dextroid17 commented 2026-10-12 00:50:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T00:50:07Z.


The behavior change here is real: fclose_nid_postfix used to always return 0 even when the underlying flush/close failed, silently converting a write failure into "successfully closed." The new /dev/full-based test is a sharp, minimal reproduction of exactly that scenario (a buffered write that only fails at flush-on-close time).

FileStream::Close() also previously threw std::runtime_error on failure instead of returning an error code, so removing that throw changes its contract from "failure is a thrown exception" to "failure is a return value" — but nothing else depended on the throw: the only other caller is freopen_nid_postfix, which already discarded Close()'s result either way, and every test caller discards it too.

One small portability note: the new test is guarded #ifndef _WIN32, which also includes macOS, where /dev/full doesn't exist — CI doesn't catch this today since the macOS job only builds the relinker, but a local macOS build of the libs tests would abort on Require(full != nullptr). Narrowing the guard to #if defined(__linux__), matching the project's existing Linux-only /dev/full test in core/relinker, would close that gap.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6115796629 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3926#issuecomment-6115796629). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-12T00:50:07Z. --- The behavior change here is real: `fclose_nid_postfix` used to always return 0 even when the underlying flush/close failed, silently converting a write failure into "successfully closed." The new `/dev/full`-based test is a sharp, minimal reproduction of exactly that scenario (a buffered write that only fails at flush-on-close time). `FileStream::Close()` also previously threw `std::runtime_error` on failure instead of returning an error code, so removing that throw changes its contract from "failure is a thrown exception" to "failure is a return value" — but nothing else depended on the throw: the only other caller is `freopen_nid_postfix`, which already discarded `Close()`'s result either way, and every test caller discards it too. One small portability note: the new test is guarded `#ifndef _WIN32`, which also includes macOS, where `/dev/full` doesn't exist — CI doesn't catch this today since the macOS job only builds the relinker, but a local macOS build of the libs tests would abort on `Require(full != nullptr)`. Narrowing the guard to `#if defined(__linux__)`, matching the project's existing Linux-only `/dev/full` test in `core/relinker`, would close that gap. Written with AI assistance.
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!3926
No description provided.