Skip to content

fix(libc): fail fseek and ftell on a pipe with ESPIPE on Windows - #4839

Closed
nicolasfalesy wants to merge 1 commit into
boykopovar:mainfrom
nicolasfalesy:fix/libc-seek-pipe-stream-windows
Closed

nicolasfalesy wants to merge 1 commit into
boykopovar:mainfrom
nicolasfalesy:fix/libc-seek-pipe-stream-windows

Conversation

@nicolasfalesy

Copy link
Copy Markdown
Contributor

What

Carries DavidSamir:fix/libc-seek-pipe-stream-windows (76cca64) from #4837, which David can't open while #4532 is open. The commit is cherry-picked onto current main unchanged, authorship kept.

Closes #4837.

On Windows, fseeko and ftello (and through them fseek, ftell, fgetpos, fsetpos and rewind) now fail with ESPIPE on a stream over a pipe before the C runtime is called, as on FreeBSD and the Linux build, so the stream's read buffer is no longer discarded. Whether the stream is a pipe is asked once with GetFileType and kept in the FileStream, and asked again after freopen. Linux is unchanged. guest_standard_streams' pipe check now runs on Windows too and is extended to every seek origin and ftello. Details and the Windows measurements are in #4837.

Tested

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 under Silent stubs in their library's technical debt file
  • 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 (fix(libc): append through a descriptor opened by fdopen in an append mode on Windows #4738 adds a helper at the same place in FileAndHeap.cpp; whichever lands second needs a small rebase, which I'll do here if this one is second)
  • Unblocks: none
  • AI-assisted: yes

@milescoviello

Copy link
Copy Markdown
Contributor

For whoever reviews: #4838 carries the same commit from #4837 (opened a minute before this one, with a Linux run added), so only one of the two needs merging.

AI-assisted: yes

@github-actions

github-actions Bot commented Oct 12, 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
#4738 core/libs/prx/libc/src/FileAndHeap.cpp L89
#4838 core/libs/prx/libc/src/FileAndHeap.cpp L89, L348, L361

@MarcZX10

Copy link
Copy Markdown
Contributor

I found the same descriptor-replacement edge case here as in #4838: FileStream::IsPipe caches its first GetFileType result. If a stream is first queried while backed by a regular file and its descriptor is later replaced by a pipe (_dup2), subsequent seeks still treat it as a file and can discard buffered bytes. I posted the concrete case and local Linux/syntax-check results on #4838 as well. The Windows-only regression was not run locally.

@nicolasfalesy

Copy link
Copy Markdown
Contributor Author

Closing as a duplicate of #4838, which carries the same commit, was opened first and has the fuller Linux run. Thanks @milescoviello.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libc: fseek and ftell succeed on a pipe and lose buffered data on Windows, where FreeBSD fails with ESPIPE; fix branch ready

4 participants