Repository navigation
fix(output): open device and pipe targets without O_TRUNC - #209
Merged
TMHSDigital merged 1 commit intoNov 10, 2026
Merged
Conversation
…l#208) Windows rejects O_TRUNC on the NUL device with ERROR_INVALID_FUNCTION, so -o NUL, -stats NUL and -sarif NUL failed with "open NUL: Incorrect function." and exit 1. Truncating a device or pipe is meaningless, so drop the flag; the direct-write branch already handles non-regular targets. Drops the Windows skip in TestCreateFileWritesNonRegularTargetDirectly: it now exercises the NUL device on Windows too. Signed-off-by: bfs2021 <[email protected]>
7 tasks
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.
Description
CreateFileopens an existing non-regular target (device, pipe) withos.O_WRONLY|os.O_TRUNC. Windows rejectsO_TRUNCon theNULdevice withERROR_INVALID_FUNCTION, so-o NUL— and the same path for-stats NUL/-sarif NUL— failed withError: creating output file: open NUL: Incorrect function.and exit 1, while-o /dev/nullworks on Linux and macOS.This drops
O_TRUNCfor that branch. Truncating a device or pipe is meaningless, and the branch already writes directly instead of going through the temp-file/rename path, so the flag has no purpose there. Regular files are untouched: they still go through the temporary file and replace the target onClose(true).Related Issue
Fixes #208
Type of Change
Root cause
os.Stat("NUL")reports a non-regular file on Windows, so this branch runs;CreateFileon the NUL device returnsERROR_INVALID_FUNCTIONwhenO_TRUNCis set. Opening without it succeeds, and writes are discarded as the device intends.Testing
CreateFile("NUL")on unpatched code returnsopen NUL: Incorrect function.TestCreateFileWritesNonRegularTargetDirectlyno longer skips on Windows and now passes against the NUL device. It still skips whenos.DevNullis a regular file.go test ./...— all packages pass on Windows/amd64 (go 1.27.3).gofmt -l internal/outputclean,go vet ./internal/output/clean.Checklist