aboutsummaryrefslogtreecommitdiff
path: root/src/os
diff options
context:
space:
mode:
Diffstat (limited to 'src/os')
-rw-r--r--src/os/dir_darwin.go10
-rw-r--r--src/os/dir_unix.go2
-rw-r--r--src/os/os_test.go4
-rw-r--r--src/os/proc.go8
4 files changed, 18 insertions, 6 deletions
diff --git a/src/os/dir_darwin.go b/src/os/dir_darwin.go
index 87797e2dda..476af6862e 100644
--- a/src/os/dir_darwin.go
+++ b/src/os/dir_darwin.go
@@ -28,7 +28,7 @@ func (f *File) readdirnames(n int) (names []string, err error) {
if f.dirinfo == nil {
dir, call, errno := f.pfd.OpenDir()
if errno != nil {
- return nil, wrapSyscallError(call, errno)
+ return nil, &PathError{call, f.name, errno}
}
f.dirinfo = &dirInfo{
dir: dir,
@@ -46,11 +46,11 @@ func (f *File) readdirnames(n int) (names []string, err error) {
var dirent syscall.Dirent
var entptr *syscall.Dirent
for len(names) < size || n == -1 {
- if res := readdir_r(d.dir, &dirent, &entptr); res != 0 {
- if syscall.Errno(res) == syscall.EINTR {
+ if errno := readdir_r(d.dir, &dirent, &entptr); errno != 0 {
+ if errno == syscall.EINTR {
continue
}
- return names, wrapSyscallError("readdir", syscall.Errno(res))
+ return names, &PathError{"readdir", f.name, errno}
}
if entptr == nil { // EOF
break
@@ -84,4 +84,4 @@ func (f *File) readdirnames(n int) (names []string, err error) {
func closedir(dir uintptr) (err error)
//go:linkname readdir_r syscall.readdir_r
-func readdir_r(dir uintptr, entry *syscall.Dirent, result **syscall.Dirent) (res int)
+func readdir_r(dir uintptr, entry *syscall.Dirent, result **syscall.Dirent) (res syscall.Errno)
diff --git a/src/os/dir_unix.go b/src/os/dir_unix.go
index e0c4989756..58ec406ab8 100644
--- a/src/os/dir_unix.go
+++ b/src/os/dir_unix.go
@@ -50,7 +50,7 @@ func (f *File) readdirnames(n int) (names []string, err error) {
d.nbuf, errno = f.pfd.ReadDirent(d.buf)
runtime.KeepAlive(f)
if errno != nil {
- return names, wrapSyscallError("readdirent", errno)
+ return names, &PathError{"readdirent", f.name, errno}
}
if d.nbuf <= 0 {
break // EOF
diff --git a/src/os/os_test.go b/src/os/os_test.go
index e8c64510f5..520916d880 100644
--- a/src/os/os_test.go
+++ b/src/os/os_test.go
@@ -688,6 +688,10 @@ func TestReaddirOfFile(t *testing.T) {
if err == nil {
t.Error("Readdirnames succeeded; want non-nil error")
}
+ var pe *PathError
+ if !errors.As(err, &pe) || pe.Path != f.Name() {
+ t.Errorf("Readdirnames returned %q; want a PathError with path %q", err, f.Name())
+ }
if len(names) > 0 {
t.Errorf("unexpected dir names in regular file: %q", names)
}
diff --git a/src/os/proc.go b/src/os/proc.go
index 7364d631f2..cbd5a6aad9 100644
--- a/src/os/proc.go
+++ b/src/os/proc.go
@@ -7,6 +7,7 @@
package os
import (
+ "internal/testlog"
"runtime"
"syscall"
)
@@ -60,6 +61,13 @@ func Getgroups() ([]int, error) {
// For portability, the status code should be in the range [0, 125].
func Exit(code int) {
if code == 0 {
+ if testlog.PanicOnExit0() {
+ // We were told to panic on calls to os.Exit(0).
+ // This is used to fail tests that make an early
+ // unexpected call to os.Exit(0).
+ panic("unexpected call to os.Exit(0) during test")
+ }
+
// Give race detector a chance to fail the program.
// Racy programs do not have the right to finish successfully.
runtime_beforeExit()