diff --git a/internal/output/file.go b/internal/output/file.go index ec45027..bd5f7e7 100644 --- a/internal/output/file.go +++ b/internal/output/file.go @@ -36,7 +36,10 @@ func CreateFile(path string) (*File, error) { keep := os.FileMode(0) if fi, err := os.Stat(path); err == nil { if !fi.Mode().IsRegular() { - f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0) + // No O_TRUNC: truncating a device or pipe is meaningless, and + // Windows rejects it on the NUL device with ERROR_INVALID_FUNCTION + // (#208), which broke -o NUL. + f, err := os.OpenFile(path, os.O_WRONLY, 0) if err != nil { return nil, err } diff --git a/internal/output/lifecycle_test.go b/internal/output/lifecycle_test.go index 413b881..a2b50d0 100644 --- a/internal/output/lifecycle_test.go +++ b/internal/output/lifecycle_test.go @@ -6,7 +6,6 @@ import ( "encoding/json" "os" "path/filepath" - "runtime" "strings" "testing" @@ -97,9 +96,6 @@ func TestCreateFileMissingDirectory(t *testing.T) { } func TestCreateFileWritesNonRegularTargetDirectly(t *testing.T) { - if runtime.GOOS == "windows" { - t.Skip("opening NUL with O_TRUNC fails on Windows") - } fi, err := os.Stat(os.DevNull) if err != nil || fi.Mode().IsRegular() { t.Skipf("%s is not a device here", os.DevNull)