| 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. |
| 4 |
|
| 5 |
package syscall |
| 6 |
|
| 7 |
import "internal/oserror" |
| 8 |
|
| 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: |
| 12 |
// |
| 13 |
// err = nil |
| 14 |
// if errno != 0 { |
| 15 |
// err = errno |
| 16 |
// } |
| 17 |
// |
| 18 |
// Errno values can be tested against error values from the os package |
| 19 |
// using errors.Is. For example: |
| 20 |
// |
| 21 |
// _, _, err := syscall.Syscall(...) |
| 22 |
// if errors.Is(err, fs.ErrNotExist) ... |
| 23 |
type Errno uintptr |
| 24 |
|
| 25 |
func (e Errno) Error() string { |
| 26 |
return Errstr(int(e)) |
| 27 |
} |
| 28 |
|
| 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 |
| 37 |
} |
| 38 |
return false |
| 39 |
} |
| 40 |
|
| 41 |
func (e Errno) Temporary() bool { |
| 42 |
return e == EINTR || e == EMFILE || e == ENFILE || e.Timeout() |
| 43 |
} |
| 44 |
|
| 45 |
func (e Errno) Timeout() bool { |
| 46 |
return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT |
| 47 |
} |