Debian Codegraph @

internal/unix/errno_windows.go

raw symbols SCIP
1 package unix
2
3 // The code in this file is derived from syscall_unix.go in the Go source code,
4 // licensed under the MIT license.
5
6 import (
7 "errors"
8 "os"
9 "syscall"
10 )
11
12 //go:generate go tool stringer -type=Errno -tags=windows -output=errno_string_windows.go
13
14 // Windows specific constants for Unix errnos.
15 //
16 // The values do not always match Linux, for example EILSEQ and EOPNOTSUPP.
17 //
18 // See https://learn.microsoft.com/en-us/cpp/c-runtime-library/errno-constants?view=msvc-170
19 const (
20 EPERM Errno = 1
21 ENOENT Errno = 2
22 ESRCH Errno = 3
23 EINTR Errno = 4
24 E2BIG Errno = 7
25 EBADF Errno = 9
26 EAGAIN Errno = 11
27 EACCES Errno = 13
28 EFAULT Errno = 14
29 EEXIST Errno = 17
30 ENODEV Errno = 19
31 EINVAL Errno = 22
32 ENFILE Errno = 23
33 EMFILE Errno = 24
34 ENOSPC Errno = 28
35 ENOSYS Errno = 40
36 ENOTEMPTY Errno = 41
37 EILSEQ Errno = 42
38 ENOTSUP Errno = 129
39 EOPNOTSUPP Errno = 130
40 EOTHER Errno = 131
41 ETIMEDOUT Errno = 138
42 EWOULDBLOCK Errno = 140
43 )
44
45 // These constants do not exist on Windows and therefore have a non-zero
46 // dummy value.
47 const (
48 ENOTSUPP Errno = Errno(syscall.APPLICATION_ERROR) + iota
49 ESTALE
50 )
51
52 // Errno is a Windows compatibility shim for Unix errnos.
53 type Errno uintptr
54
55 func (e Errno) Error() string {
56 return e.String()
57 }
58
59 func (e Errno) Is(target error) bool {
60 switch target {
61 case os.ErrPermission:
62 return e == EACCES || e == EPERM
63 case os.ErrExist:
64 return e == EEXIST || e == ENOTEMPTY
65 case os.ErrNotExist:
66 return e == ENOENT
67 case errors.ErrUnsupported:
68 return e == ENOSYS || e == ENOTSUP || e == EOPNOTSUPP
69 }
70 return false
71 }
72
73 func (e Errno) Temporary() bool {
74 return e == EINTR || e == EMFILE || e == ENFILE || e.Timeout()
75 }
76
77 func (e Errno) Timeout() bool {
78 return e == EAGAIN || e == EWOULDBLOCK || e == ETIMEDOUT
79 }