libc: a failed fseek on Windows clears EOF and ungetc pushback, and gives errno 29 on pipes, where FreeBSD fails with EINVAL first; fix branch ready #5251
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by husseinkad on 2026-10-13T15:36:05Z.
A failed
fseeko(and sofseek) on Windows clears the stream's end-of-file flag and drops anyungetcpushback before it fails, and on a pipe it setserrnoto 29 (the host'sESPIPE) where FreeBSD givesEINVAL(22) for a negative target. FreeBSD 11.4fseek.crejects a negativeSEEK_SETorSEEK_CURtarget withEINVALbefore touching the stream, so the EOF state and the pushed-back character survive a failed seek. A guest that retries after a failed seek, or reads the pushed-back byte afterwards, loses data here.Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/libc-failed-seek-state (one commit on a recent main:
libc/src/FileAndHeap.cpp,tests/GuestStandardStreams.cppwith a newCheckFailedSeekKeepsState, and oneTechnicalDebt.mdline).fseekonow pre-checks theSEEK_SETandSEEK_CURtargets (using the position after pushback) and returnsEINVAL, orEOVERFLOWwhen aSEEK_CURsum overflows, without touching the stream.Checks:
guest_standard_streamsandfile_streamspass.refill/fgetc/fgets/fread/fseek/ftell/ungetc/clearerr/rewindcode: a failed negativeSEEK_SETorSEEK_CURnow keeps EOF and pushback, theSEEK_CURafterungetcreports the rightftell, and on pipes the errno is 22 where main gave 29. No real regression: the other differences in the traces are existing host C runtime bugs that main's buffer flush happened to hide.check_conventions.pyis clean andpr_overlap.pyfinds no overlap; #4837 (closed) coveredESPIPEon pipes, not this. The branch merges cleanly alone; with the separatefix/libc-eof-stickybranch it conflicts only in two appended places (the testmainand the debt file).Not fixed here (listed in
TechnicalDebt.md): aSEEK_ENDtarget before the start of the file still clears EOF and pushback in the host before failing (FreeBSD keeps both);fseeko(MAX - 1, SEEK_END)returns 22 where FreeBSD returns 84; reading after a seek to a huge offset setsferrorwith errno 22 instead of EOF;SEEK_CURafter anungetcat offset 0 succeeds where FreeBSD givesESPIPE; a secondungetcfails andungetcthenrewindreturns the pushed byte (host C runtime limits). Only Windows was built and run.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T16:26:43Z.
Implemented and opened as #5282: https://github.com/boykopovar/AnyPS5/pull/5282. Linux
guest_standard_streamsandfile_streamstests pass (2/2), including negative absolute seek on a pipe; conventions checks pass. I did not run the Windows build locally.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:32Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. #5282 is closed for the same reason. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.