2011-04-07 19:09:10 +02:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2011-10-27 01:57:58 +02:00
|
|
|
// +build darwin freebsd linux openbsd windows
|
|
|
|
|
2011-04-07 19:09:10 +02:00
|
|
|
package os
|
|
|
|
|
|
|
|
import syscall "syscall"
|
|
|
|
|
|
|
|
// Errno is the Unix error number. Names such as EINVAL are simple
|
2011-12-03 03:17:34 +01:00
|
|
|
// wrappers to convert the error number into an error.
|
2011-04-07 19:09:10 +02:00
|
|
|
type Errno int64
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func (e Errno) Error() string { return syscall.Errstr(int(e)) }
|
2011-04-07 19:09:10 +02:00
|
|
|
|
|
|
|
func (e Errno) Temporary() bool {
|
2011-09-16 17:47:21 +02:00
|
|
|
return e == Errno(syscall.EINTR) || e == Errno(syscall.EMFILE) || e.Timeout()
|
2011-04-07 19:09:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e Errno) Timeout() bool {
|
|
|
|
return e == Errno(syscall.EAGAIN) || e == Errno(syscall.EWOULDBLOCK) || e == Errno(syscall.ETIMEDOUT)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Commonly known Unix errors.
|
|
|
|
var (
|
2011-12-03 03:17:34 +01:00
|
|
|
EPERM error = Errno(syscall.EPERM)
|
|
|
|
ENOENT error = Errno(syscall.ENOENT)
|
|
|
|
ESRCH error = Errno(syscall.ESRCH)
|
|
|
|
EINTR error = Errno(syscall.EINTR)
|
|
|
|
EIO error = Errno(syscall.EIO)
|
|
|
|
ENXIO error = Errno(syscall.ENXIO)
|
|
|
|
E2BIG error = Errno(syscall.E2BIG)
|
|
|
|
ENOEXEC error = Errno(syscall.ENOEXEC)
|
|
|
|
EBADF error = Errno(syscall.EBADF)
|
|
|
|
ECHILD error = Errno(syscall.ECHILD)
|
|
|
|
EDEADLK error = Errno(syscall.EDEADLK)
|
|
|
|
ENOMEM error = Errno(syscall.ENOMEM)
|
|
|
|
EACCES error = Errno(syscall.EACCES)
|
|
|
|
EFAULT error = Errno(syscall.EFAULT)
|
|
|
|
EBUSY error = Errno(syscall.EBUSY)
|
|
|
|
EEXIST error = Errno(syscall.EEXIST)
|
|
|
|
EXDEV error = Errno(syscall.EXDEV)
|
|
|
|
ENODEV error = Errno(syscall.ENODEV)
|
|
|
|
ENOTDIR error = Errno(syscall.ENOTDIR)
|
|
|
|
EISDIR error = Errno(syscall.EISDIR)
|
|
|
|
EINVAL error = Errno(syscall.EINVAL)
|
|
|
|
ENFILE error = Errno(syscall.ENFILE)
|
|
|
|
EMFILE error = Errno(syscall.EMFILE)
|
|
|
|
ENOTTY error = Errno(syscall.ENOTTY)
|
|
|
|
EFBIG error = Errno(syscall.EFBIG)
|
|
|
|
ENOSPC error = Errno(syscall.ENOSPC)
|
|
|
|
ESPIPE error = Errno(syscall.ESPIPE)
|
|
|
|
EROFS error = Errno(syscall.EROFS)
|
|
|
|
EMLINK error = Errno(syscall.EMLINK)
|
|
|
|
EPIPE error = Errno(syscall.EPIPE)
|
|
|
|
EAGAIN error = Errno(syscall.EAGAIN)
|
|
|
|
EDOM error = Errno(syscall.EDOM)
|
|
|
|
ERANGE error = Errno(syscall.ERANGE)
|
|
|
|
EADDRINUSE error = Errno(syscall.EADDRINUSE)
|
|
|
|
ECONNREFUSED error = Errno(syscall.ECONNREFUSED)
|
|
|
|
ENAMETOOLONG error = Errno(syscall.ENAMETOOLONG)
|
|
|
|
EAFNOSUPPORT error = Errno(syscall.EAFNOSUPPORT)
|
|
|
|
ETIMEDOUT error = Errno(syscall.ETIMEDOUT)
|
|
|
|
ENOTCONN error = Errno(syscall.ENOTCONN)
|
2011-04-07 19:09:10 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// SyscallError records an error from a specific system call.
|
|
|
|
type SyscallError struct {
|
|
|
|
Syscall string
|
|
|
|
Errno Errno
|
|
|
|
}
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
func (e *SyscallError) Error() string { return e.Syscall + ": " + e.Errno.Error() }
|
2011-04-07 19:09:10 +02:00
|
|
|
|
|
|
|
// Note: If the name of the function NewSyscallError changes,
|
|
|
|
// pkg/go/doc/doc.go should be adjusted since it hardwires
|
|
|
|
// this name in a heuristic.
|
|
|
|
|
2011-12-03 03:17:34 +01:00
|
|
|
// NewSyscallError returns, as an error, a new SyscallError
|
2011-04-07 19:09:10 +02:00
|
|
|
// with the given system call name and error details.
|
|
|
|
// As a convenience, if errno is 0, NewSyscallError returns nil.
|
2011-12-03 03:17:34 +01:00
|
|
|
func NewSyscallError(syscall string, errno int) error {
|
2011-04-07 19:09:10 +02:00
|
|
|
if errno == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &SyscallError{syscall, Errno(errno)}
|
|
|
|
}
|
|
|
|
|
|
|
|
func iserror(errno int) bool {
|
|
|
|
return errno != 0
|
|
|
|
}
|