1// Copyright 2017 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package exec
6
7import (
8	"io/fs"
9	"syscall"
10)
11
12// skipStdinCopyError optionally specifies a function which reports
13// whether the provided stdin copy error should be ignored.
14func skipStdinCopyError(err error) bool {
15	// Ignore ERROR_BROKEN_PIPE and ERROR_NO_DATA errors copying
16	// to stdin if the program completed successfully otherwise.
17	// See Issue 20445.
18	const _ERROR_NO_DATA = syscall.Errno(0xe8)
19	pe, ok := err.(*fs.PathError)
20	return ok &&
21		pe.Op == "write" && pe.Path == "|1" &&
22		(pe.Err == syscall.ERROR_BROKEN_PIPE || pe.Err == _ERROR_NO_DATA)
23}
24