diff options
author | gVisor bot <gvisor-bot@google.com> | 2021-06-22 22:57:48 +0000 |
---|---|---|
committer | gVisor bot <gvisor-bot@google.com> | 2021-06-22 22:57:48 +0000 |
commit | c6031eb481baf57849c45c6ffde27efc89398c4c (patch) | |
tree | 1cd27d85a44a8a5fe8f210ef3feed3e35699cb75 /pkg/errors/linuxerr | |
parent | d909242b0d797db387131912b51373fda7608e95 (diff) | |
parent | e1dc1c78e7a523fc64ca28bed60a9a40ea1de46a (diff) |
Merge release-20210614.0-14-ge1dc1c78e (automated)
Diffstat (limited to 'pkg/errors/linuxerr')
-rw-r--r-- | pkg/errors/linuxerr/linuxerr.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/pkg/errors/linuxerr/linuxerr.go b/pkg/errors/linuxerr/linuxerr.go index bbdcdecd0..9246f2e89 100644 --- a/pkg/errors/linuxerr/linuxerr.go +++ b/pkg/errors/linuxerr/linuxerr.go @@ -20,6 +20,7 @@ package linuxerr import ( "fmt" + "golang.org/x/sys/unix" "gvisor.dev/gvisor/pkg/abi/linux/errno" "gvisor.dev/gvisor/pkg/errors" ) @@ -325,3 +326,22 @@ func ErrorFromErrno(e errno.Errno) *errors.Error { } panic(fmt.Sprintf("invalid error requested with errno: %d", e)) } + +// Equals compars a linuxerr to a given error +// TODO(b/34162363): Remove when syserror is removed. +func Equals(e *errors.Error, err error) bool { + if err == nil { + return e == NOERROR || e == nil + } + if e == nil { + return err == NOERROR || err == unix.Errno(0) + } + + switch err.(type) { + case *errors.Error: + return e == err + case unix.Errno, error: + return unix.Errno(e.Errno()) == err + } + return false +} |