2011-12-15 08:12:03 +01: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.
|
|
|
|
|
|
|
|
package syscall
|
|
|
|
|
2019-09-06 20:12:46 +02:00
|
|
|
import "internal/oserror"
|
|
|
|
|
2011-12-15 08:12:03 +01:00
|
|
|
// An Errno is an unsigned number describing an error condition.
|
2020-12-23 18:57:37 +01:00
|
|
|
// It implements the error interface. The zero Errno is by convention
|
2011-12-15 08:12:03 +01:00
|
|
|
// a non-error, so code to convert from Errno to error should use:
|
|
|
|
// err = nil
|
|
|
|
// if errno != 0 {
|
|
|
|
// err = errno
|
|
|
|
// }
|
2020-01-03 00:05:27 +01:00
|
|
|
//
|
|
|
|
// Errno values can be tested against error values from the os package
|
|
|
|
// using errors.Is. For example:
|
|
|
|
//
|
|
|
|
// _, _, err := syscall.Syscall(...)
|
2020-12-23 18:57:37 +01:00
|
|
|
// if errors.Is(err, fs.ErrNotExist) ...
|
2011-12-15 08:12:03 +01:00
|
|
|
type Errno uintptr
|
|
|
|
|
|
|
|
func (e Errno) Error() string {
|
|
|
|
return Errstr(int(e))
|
|
|
|
}
|
|
|
|
|
2019-09-06 20:12:46 +02:00
|
|
|
func (e Errno) Is(target error) bool {
|
|
|
|
switch target {
|
|
|
|
case oserror.ErrPermission:
|
|
|
|
return e == EACCES || e == EPERM
|
|
|
|
case oserror.ErrExist:
|
|
|
|
return e == EEXIST || e == ENOTEMPTY
|
|
|
|
case oserror.ErrNotExist:
|
|
|
|
return e == ENOENT
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2011-12-15 08:12:03 +01:00
|
|
|
func (e Errno) Temporary() bool {
|
2020-01-03 00:05:27 +01:00
|
|
|
return e == EINTR || e == EMFILE || e == ENFILE || e.Timeout()
|
2011-12-15 08:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (e Errno) Timeout() bool {
|
|
|
|
return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
|
|
|
|
}
|