Files
AnyPS5/docs/dev/debt/changes/fix-libc-closed-stream-write-errors.md
brajankwandbrajan.kw 484e8e6b77 fix(libc): fail fputs, fputc and fprintf on a closed stream as a PS5 does (#22047)
* fix(libc): fail fputs, fputc and fprintf on a closed stream as a PS5 does
* test(libc): expect fputc on a stream fcloseall closed to leave errno unchanged

Co-authored-by: brajan.kw <brajan.kwiatkowski@protonmail.com>
2026-12-04 08:29:48 +13:00

738 B

libc

change [freopen of a closed stream]

  • freopen of a closed stream (libc) opens the file on a new host descriptor, so fileno after fclose(stdout) and freopen(path, mode, stdout) is whatever the host hands out, where a PS5 takes the lowest free descriptor. The stream object is kept and reopened as there, and a missing path (ENOENT), an overlong one (ENAMETOOLONG) and a null filename (EBADF) answer as measured on a console. On the closed stream fputs and fputc (which putc, putchar and __swbuf forward to) return -1 leaving errno unchanged and fprintf gives EINVAL, as measured on the console; the other writes, unmeasured, answer EBADF.