os, syscall: fix errno in Seek on windows

Current implementation use EPIPE as an error for Seek on pipes.
According to http://pubs.opengroup.org/onlinepubs/009695399/functions/lseek.html,
it should use ESPIPE instead.

Fixes #20066

Change-Id: I24c3b95be946bc19a287d6b10f447b034a9a1283
Reviewed-on: https://go-review.googlesource.com/41311
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Hiroshi Ioka 2017-04-21 17:10:58 +09:00 committed by Ian Lance Taylor
parent c202d4d303
commit ffd7cfce4b
2 changed files with 27 additions and 1 deletions

View File

@ -1286,6 +1286,32 @@ func TestSeek(t *testing.T) {
}
}
func TestSeekError(t *testing.T) {
switch runtime.GOOS {
case "plan9", "nacl":
t.Skipf("skipping test on %v", runtime.GOOS)
}
r, w, err := Pipe()
if err != nil {
t.Fatal(err)
}
_, err = r.Seek(0, 0)
if err == nil {
t.Fatal("Seek on pipe should fail")
}
if perr, ok := err.(*PathError); !ok || perr.Err != syscall.ESPIPE {
t.Errorf("Seek returned error %v, want &PathError{Err: syscall.ESPIPE}", err)
}
_, err = w.Seek(0, 0)
if err == nil {
t.Fatal("Seek on pipe should fail")
}
if perr, ok := err.(*PathError); !ok || perr.Err != syscall.ESPIPE {
t.Errorf("Seek returned error %v, want &PathError{Err: syscall.ESPIPE}", err)
}
}
type openErrorTest struct {
path string
mode int

View File

@ -348,7 +348,7 @@ func Seek(fd Handle, offset int64, whence int) (newoffset int64, err error) {
// use GetFileType to check pipe, pipe can't do seek
ft, _ := GetFileType(fd)
if ft == FILE_TYPE_PIPE {
return 0, EPIPE
return 0, ESPIPE
}
rlo, e := SetFilePointer(fd, lo, &hi, w)
if e != nil {