From: Hiroshi Ioka Date: Fri, 21 Apr 2017 08:10:58 +0000 (+0900) Subject: os, syscall: fix errno in Seek on windows X-Git-Tag: go1.9beta1~532 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=ffd7cfce4b6113280783136b6580f5bca55e27e2;p=gostls13.git 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 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- diff --git a/src/os/os_test.go b/src/os/os_test.go index a7fbfa4cb3..895a3e2bc5 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -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 diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 19a7deb230..7f92bf7ca4 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -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 {