go.sys/unix: use syscall.Errno for errors

If we use a local type, it won't compare properly with errors from
the rest of the standard library. Errors are the one type from syscall
that propagates through the system, so it's important to have only
one type for them.

Ditto for syscall.Signal.

LGTM=dave
R=rsc, dave
CC=golang-codereviews
https://golang.org/cl/123490043
This commit is contained in:
Rob Pike
2014-08-15 09:57:24 -07:00
parent 70c4b52aa0
commit dc3c21c62b
58 changed files with 2546 additions and 2491 deletions
+5 -16
View File
@@ -11,6 +11,7 @@ package unix
import (
"runtime"
"sync"
"syscall"
"unsafe"
)
@@ -63,18 +64,6 @@ import (
var ForkLock sync.RWMutex
// StringSlicePtr is deprecated. Use SlicePtrFromStrings instead.
// If any string contains a NUL byte this function panics instead
// of returning an error.
func StringSlicePtr(ss []string) []*byte {
bb := make([]*byte, len(ss)+1)
for i := 0; i < len(ss); i++ {
bb[i] = StringBytePtr(ss[i])
}
bb[len(ss)] = nil
return bb
}
// SlicePtrFromStrings converts a slice of strings to a slice of
// pointers to NUL-terminated byte slices. If any string contains
// a NUL byte, it returns (nil, EINVAL).
@@ -130,7 +119,7 @@ var zeroSysProcAttr SysProcAttr
func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error) {
var p [2]int
var n int
var err1 Errno
var err1 syscall.Errno
var wstatus WaitStatus
if attr == nil {
@@ -190,7 +179,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
// Kick off child.
pid, err1 = forkAndExecInChild(argv0p, argvp, envvp, chroot, dir, attr, sys, p[1])
if err1 != 0 {
err = Errno(err1)
err = syscall.Errno(err1)
goto error
}
ForkLock.Unlock()
@@ -201,7 +190,7 @@ func forkExec(argv0 string, argv []string, attr *ProcAttr) (pid int, err error)
Close(p[0])
if err != nil || n != 0 {
if n == int(unsafe.Sizeof(err1)) {
err = Errno(err1)
err = syscall.Errno(err1)
}
if err == nil {
err = EPIPE
@@ -257,5 +246,5 @@ func Exec(argv0 string, argv []string, envv []string) (err error) {
uintptr(unsafe.Pointer(argv0p)),
uintptr(unsafe.Pointer(&argvp[0])),
uintptr(unsafe.Pointer(&envvp[0])))
return Errno(err1)
return syscall.Errno(err1)
}