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