syscall: gofmt
[official-gcc.git] / libgo / go / syscall / syscall_errno.go
blob68fe49521a5e8348bd5d24d3a0748b5c3dd1e948
1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 package syscall
7 import "internal/oserror"
9 // An Errno is an unsigned number describing an error condition.
10 // It implements the error interface. The zero Errno is by convention
11 // a non-error, so code to convert from Errno to error should use:
13 // err = nil
14 // if errno != 0 {
15 // err = errno
16 // }
18 // Errno values can be tested against error values from the os package
19 // using errors.Is. For example:
21 // _, _, err := syscall.Syscall(...)
22 // if errors.Is(err, fs.ErrNotExist) ...
23 type Errno uintptr
25 func (e Errno) Error() string {
26 return Errstr(int(e))
29 func (e Errno) Is(target error) bool {
30 switch target {
31 case oserror.ErrPermission:
32 return e == EACCES || e == EPERM
33 case oserror.ErrExist:
34 return e == EEXIST || e == ENOTEMPTY
35 case oserror.ErrNotExist:
36 return e == ENOENT
38 return false
41 func (e Errno) Temporary() bool {
42 return e == EINTR || e == EMFILE || e == ENFILE || e.Timeout()
45 func (e Errno) Timeout() bool {
46 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT