]> Cypherpunks repositories - gostls13.git/commitdiff
os, syscall: fix errno in Seek on windows
authorHiroshi Ioka <hirochachacha@gmail.com>
Fri, 21 Apr 2017 08:10:58 +0000 (17:10 +0900)
committerIan Lance Taylor <iant@golang.org>
Sat, 22 Apr 2017 01:06:09 +0000 (01:06 +0000)
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>

src/os/os_test.go
src/syscall/syscall_windows.go

index a7fbfa4cb3fbf58d33b83570b45265e3c42aca56..895a3e2bc5c2fe1c080b66feb0c08e7c32fcf59a 100644 (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
index 19a7deb2306391fa3fa282cd11e46bb83653dfa5..7f92bf7ca4d61e99114097edb17ea8c86a8ac9d5 100644 (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 {