Repository navigation
fix(libc): append through a descriptor opened by fdopen in an append mode on Windows - #4738
Merged
oneandonlydean merged 1 commit intoOct 13, 2026
Conversation
10 tasks done
|
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.
|
10 tasks done
10 tasks done
Contributor
|
Windows test: head AI-assisted (Claude Code). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes #4735. Carries @DavidSamir's fix branch from that issue (
DavidSamir:fix/libc-fdopen-append-windows,ca4e5910), keeping the commit and its authorship; it cherry-picks onto currentmainwithout changes.On Windows a stream made with
fdopen(fd, "a")(also"ab","a+","ae") wrote at the descriptor's current offset and overwrote what was there, because the C runtime's_fdopendoes not turn on append for an existing descriptor; a program that wraps its log or save file this way replaced the start of the file on each run. FreeBSD'sfdopen(lib/libc/stdio/fdopen.c) handles exactly this: "If opened for appending, but underlying descriptor does not have O_APPEND bit set, assert __SAPP so that __swrite() caller will _sseek() to the end before write." Before_fdopen, the append modes now reopen a duplicate of the descriptor's handle with_O_APPENDand move it onto the same descriptor number with_dup2, so the number, the file object, its offset, locks and sharing are kept and the C runtime seeks to the end before each write. Descriptors 0 to 2 and descriptors that are not disk files are left as they are. Linux is unchanged.guest_standard_streamsgainsCheckDescriptorAppend: for"a","ab","a+"and"ae", a descriptor on a file is moved to offset 2 and wrapped; a byte written and flushed, and one more written afterfseek(0, SEEK_SET), must both land at the end, andfilenomust still be the descriptor.Tested
main'sFileAndHeap.cppthe new check fails and with the fixguest_standard_streamspasses 5/5; probes of 313, 884 and 122 lines over the stream and descriptor functions differ frommainonly in the append contents; eleven catalog titles that importfdopenend the same way with both sets of libraries; fullctest995/995; no measurable cost.main0142215.guest_standard_streams,guest_filesystemandguest_kernel_fcntlpass, and all 312guest_*tests pass in two runs. The new check also passes withmain'sFileAndHeap.cpp, as expected since only the Windows path changes. I could not run Windows myself.tools/check_conventions.py --base upstream/mainpasses. The issue notes that fix(libc): reject incompatible fdopen access modes on Windows #4728 adds lines at the same places, so whichever lands second needs a small rebase.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code