mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: let ENOSYS, ENOTSUP and EOPNOTSUPP implement errors.ErrUnsupported
As suggested by Bryan, also update (Errno).Is on windows to include the missing oserror cases that are covered on other platforms. Quoting Bryan: > Windows syscalls don't actually return those errors, but the dummy Errno > constants defined on Windows should still have the same meaning as on > Unix. Updates #41198 Change-Id: I15441abde4a7ebaa3c6518262c052530cd2add4b Reviewed-on: https://go-review.googlesource.com/c/go/+/476875 TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Bryan Mills <bcmills@google.com> Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
8377f2014d
commit
75c2e97c3c
5 changed files with 26 additions and 17 deletions
|
|
@ -103,8 +103,8 @@ func UTF16PtrFromString(s string) (*uint16, error) {
|
|||
|
||||
// Errno is the Windows error number.
|
||||
//
|
||||
// Errno values can be tested against error values from the os package
|
||||
// using errors.Is. For example:
|
||||
// Errno values can be tested against error values using errors.Is.
|
||||
// For example:
|
||||
//
|
||||
// _, _, err := syscall.Syscall(...)
|
||||
// if errors.Is(err, fs.ErrNotExist) ...
|
||||
|
|
@ -147,17 +147,25 @@ const _ERROR_BAD_NETPATH = Errno(53)
|
|||
func (e Errno) Is(target error) bool {
|
||||
switch target {
|
||||
case oserror.ErrPermission:
|
||||
return e == ERROR_ACCESS_DENIED
|
||||
return e == ERROR_ACCESS_DENIED ||
|
||||
e == EACCES ||
|
||||
e == EPERM
|
||||
case oserror.ErrExist:
|
||||
return e == ERROR_ALREADY_EXISTS ||
|
||||
e == ERROR_DIR_NOT_EMPTY ||
|
||||
e == ERROR_FILE_EXISTS
|
||||
e == ERROR_FILE_EXISTS ||
|
||||
e == EEXIST ||
|
||||
e == ENOTEMPTY
|
||||
case oserror.ErrNotExist:
|
||||
return e == ERROR_FILE_NOT_FOUND ||
|
||||
e == _ERROR_BAD_NETPATH ||
|
||||
e == ERROR_PATH_NOT_FOUND
|
||||
e == ERROR_PATH_NOT_FOUND ||
|
||||
e == ENOENT
|
||||
case errorspkg.ErrUnsupported:
|
||||
return e == EWINDOWS
|
||||
return e == ENOSYS ||
|
||||
e == ENOTSUP ||
|
||||
e == EOPNOTSUPP ||
|
||||
e == EWINDOWS
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue