Commit b87d025a authored by Rob Pike's avatar Rob Pike

go.sys/plan9: use syscall.ErrorString 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.
Will apply the corresponding change to the other packages once
this is approved.

Also delete some deprecated code. This is a new package; no need
to carry the past.

LGTM=rsc
R=rsc
CC=golang-codereviews
https://golang.org/cl/126250043
parent 0c079811
......@@ -61,18 +61,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).
......@@ -323,11 +311,6 @@ childerror:
for {
RawSyscall(SYS_EXITS, 0, 0, 0)
}
// Calling panic is not actually safe,
// but the for loop above won't break
// and this shuts up the compiler.
panic("unreached")
}
func cexecPipe(p []int) error {
......
......@@ -17,20 +17,10 @@
// For details of the functions and data types in this package consult
// the manuals for the appropriate operating system.
// These calls return err == nil to indicate success; otherwise
// err represents an operating system error describing the failure.
// err represents an operating system error describing the failure and
// holds a value of type syscall.ErrorString.
package plan9
// StringByteSlice is deprecated. Use ByteSliceFromString instead.
// If s contains a NUL byte this function panics instead of
// returning an error.
func StringByteSlice(s string) []byte {
a, err := ByteSliceFromString(s)
if err != nil {
panic("syscall: string with NUL passed to StringByteSlice")
}
return a
}
// ByteSliceFromString returns a NUL-terminated slice of bytes
// containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
......@@ -45,11 +35,6 @@ func ByteSliceFromString(s string) ([]byte, error) {
return a, nil
}
// StringBytePtr is deprecated. Use BytePtrFromString instead.
// If s contains a NUL byte this function panics instead of
// returning an error.
func StringBytePtr(s string) *byte { return &StringByteSlice(s)[0] }
// BytePtrFromString returns a pointer to a NUL-terminated array of
// bytes containing the text of s. If s contains a NUL byte at any
// location, it returns (nil, EINVAL).
......
......@@ -11,25 +11,10 @@
package plan9
import "unsafe"
const ImplementsGetwd = true
// ErrorString implements Error's String method by returning itself.
type ErrorString string
func (e ErrorString) Error() string { return string(e) }
// NewError converts s to an ErrorString, which satisfies the Error interface.
func NewError(s string) error { return ErrorString(s) }
func (e ErrorString) Temporary() bool {
return e == EINTR || e == EMFILE || e.Timeout()
}
func (e ErrorString) Timeout() bool {
return e == EBUSY || e == ETIMEDOUT
}
import (
"syscall"
"unsafe"
)
// A Note is a string describing a process note.
// It implements the os.Signal interface.
......@@ -51,8 +36,8 @@ var (
// creation of IPv6 sockets to return EAFNOSUPPORT.
var SocketDisableIPv6 bool
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err ErrorString)
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err ErrorString)
func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
......@@ -249,7 +234,7 @@ func Unmount(name, old string) (err error) {
oldptr := uintptr(unsafe.Pointer(oldp))
var r0 uintptr
var e ErrorString
var e syscall.ErrorString
// bind(2) man page: If name is zero, everything bound or mounted upon old is unbound or unmounted.
if name == "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment