diff options
| author | Keith Randall <khr@golang.org> | 2015-03-02 20:16:48 -0800 |
|---|---|---|
| committer | Keith Randall <khr@golang.org> | 2015-03-03 17:46:36 +0000 |
| commit | f584c05fcc38fef1582681a7e2841b725f0a827d (patch) | |
| tree | 5a96b88327f816c5e32b57090382df4b10793153 /src/runtime/runtime_test.go | |
| parent | 74e88dfdeebef392d52d3f792e2071b058c1e231 (diff) | |
| download | go-f584c05fcc38fef1582681a7e2841b725f0a827d.tar.xz | |
runtime: Update open/close/read/write to return -1 on error.
Error detection code copied from syscall, where presumably
we actually do it right.
Note that we throw the errno away. The runtime doesn't use it.
Fixes #10052
Change-Id: I8de77dda6bf287276b137646c26b84fa61554ec8
Reviewed-on: https://go-review.googlesource.com/6571
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
Diffstat (limited to 'src/runtime/runtime_test.go')
| -rw-r--r-- | src/runtime/runtime_test.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index 09884200e4..983442f1db 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -292,3 +292,29 @@ func TestTrailingZero(t *testing.T) { t.Errorf("sizeof(%#v)==%d, want 0", T5{}, unsafe.Sizeof(T5{})) } } + +func TestBadOpen(t *testing.T) { + if GOOS == "windows" || GOOS == "nacl" { + t.Skip("skipping OS that doesn't have open/read/write/close") + } + // make sure we get the correct error code if open fails. Same for + // read/write/close on the resulting -1 fd. See issue 10052. + nonfile := []byte("/notreallyafile") + fd := Open(&nonfile[0], 0, 0) + if fd != -1 { + t.Errorf("open(\"%s\")=%d, want -1", string(nonfile), fd) + } + var buf [32]byte + r := Read(-1, unsafe.Pointer(&buf[0]), int32(len(buf))) + if r != -1 { + t.Errorf("read()=%d, want -1", r) + } + w := Write(^uintptr(0), unsafe.Pointer(&buf[0]), int32(len(buf))) + if w != -1 { + t.Errorf("write()=%d, want -1", w) + } + c := Close(-1) + if c != -1 { + t.Errorf("close()=%d, want -1", c) + } +} |
