1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2016 Damien P. George
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 #ifndef MICROPY_INCLUDED_PY_MPERRNO_H
27 #define MICROPY_INCLUDED_PY_MPERRNO_H
28 
29 #include "py/mpconfig.h"
30 
31 #if MICROPY_USE_INTERNAL_ERRNO
32 
33 // MP_Exxx errno's are defined directly as numeric values
34 // (Linux constants are used as a reference)
35 
36 #define MP_EPERM              (1) // Operation not permitted
37 #define MP_ENOENT             (2) // No such file or directory
38 #define MP_ESRCH              (3) // No such process
39 #define MP_EINTR              (4) // Interrupted system call
40 #define MP_EIO                (5) // I/O error
41 #define MP_ENXIO              (6) // No such device or address
42 #define MP_E2BIG              (7) // Argument list too long
43 #define MP_ENOEXEC            (8) // Exec format error
44 #define MP_EBADF              (9) // Bad file number
45 #define MP_ECHILD            (10) // No child processes
46 #define MP_EAGAIN            (11) // Try again
47 #define MP_ENOMEM            (12) // Out of memory
48 #define MP_EACCES            (13) // Permission denied
49 #define MP_EFAULT            (14) // Bad address
50 #define MP_ENOTBLK           (15) // Block device required
51 #define MP_EBUSY             (16) // Device or resource busy
52 #define MP_EEXIST            (17) // File exists
53 #define MP_EXDEV             (18) // Cross-device link
54 #define MP_ENODEV            (19) // No such device
55 #define MP_ENOTDIR           (20) // Not a directory
56 #define MP_EISDIR            (21) // Is a directory
57 #define MP_EINVAL            (22) // Invalid argument
58 #define MP_ENFILE            (23) // File table overflow
59 #define MP_EMFILE            (24) // Too many open files
60 #define MP_ENOTTY            (25) // Not a typewriter
61 #define MP_ETXTBSY           (26) // Text file busy
62 #define MP_EFBIG             (27) // File too large
63 #define MP_ENOSPC            (28) // No space left on device
64 #define MP_ESPIPE            (29) // Illegal seek
65 #define MP_EROFS             (30) // Read-only file system
66 #define MP_EMLINK            (31) // Too many links
67 #define MP_EPIPE             (32) // Broken pipe
68 #define MP_EDOM              (33) // Math argument out of domain of func
69 #define MP_ERANGE            (34) // Math result not representable
70 #define MP_EWOULDBLOCK  MP_EAGAIN // Operation would block
71 #define MP_EOPNOTSUPP        (95) // Operation not supported on transport endpoint
72 #define MP_EAFNOSUPPORT      (97) // Address family not supported by protocol
73 #define MP_EADDRINUSE        (98) // Address already in use
74 #define MP_ECONNABORTED     (103) // Software caused connection abort
75 #define MP_ECONNRESET       (104) // Connection reset by peer
76 #define MP_ENOBUFS          (105) // No buffer space available
77 #define MP_EISCONN          (106) // Transport endpoint is already connected
78 #define MP_ENOTCONN         (107) // Transport endpoint is not connected
79 #define MP_ETIMEDOUT        (110) // Connection timed out
80 #define MP_ECONNREFUSED     (111) // Connection refused
81 #define MP_EHOSTUNREACH     (113) // No route to host
82 #define MP_EALREADY         (114) // Operation already in progress
83 #define MP_EINPROGRESS      (115) // Operation now in progress
84 #define MP_ECANCELED        (125) // Operation canceled
85 
86 #else
87 
88 // MP_Exxx errno's are defined in terms of system supplied ones
89 
90 #include <errno.h>
91 
92 #define MP_EPERM            EPERM
93 #define MP_ENOENT           ENOENT
94 #define MP_ESRCH            ESRCH
95 #define MP_EINTR            EINTR
96 #define MP_EIO              EIO
97 #define MP_ENXIO            ENXIO
98 #define MP_E2BIG            E2BIG
99 #define MP_ENOEXEC          ENOEXEC
100 #define MP_EBADF            EBADF
101 #define MP_ECHILD           ECHILD
102 #define MP_EAGAIN           EAGAIN
103 #define MP_ENOMEM           ENOMEM
104 #define MP_EACCES           EACCES
105 #define MP_EFAULT           EFAULT
106 #define MP_ENOTBLK          ENOTBLK
107 #define MP_EBUSY            EBUSY
108 #define MP_EEXIST           EEXIST
109 #define MP_EXDEV            EXDEV
110 #define MP_ENODEV           ENODEV
111 #define MP_ENOTDIR          ENOTDIR
112 #define MP_EISDIR           EISDIR
113 #define MP_EINVAL           EINVAL
114 #define MP_ENFILE           ENFILE
115 #define MP_EMFILE           EMFILE
116 #define MP_ENOTTY           ENOTTY
117 #define MP_ETXTBSY          ETXTBSY
118 #define MP_EFBIG            EFBIG
119 #define MP_ENOSPC           ENOSPC
120 #define MP_ESPIPE           ESPIPE
121 #define MP_EROFS            EROFS
122 #define MP_EMLINK           EMLINK
123 #define MP_EPIPE            EPIPE
124 #define MP_EDOM             EDOM
125 #define MP_ERANGE           ERANGE
126 #define MP_EWOULDBLOCK      EWOULDBLOCK
127 #define MP_EOPNOTSUPP       EOPNOTSUPP
128 #define MP_EAFNOSUPPORT     EAFNOSUPPORT
129 #define MP_EADDRINUSE       EADDRINUSE
130 #define MP_ECONNABORTED     ECONNABORTED
131 #define MP_ECONNRESET       ECONNRESET
132 #define MP_ENOBUFS          ENOBUFS
133 #define MP_EISCONN          EISCONN
134 #define MP_ENOTCONN         ENOTCONN
135 #define MP_ETIMEDOUT        ETIMEDOUT
136 #define MP_ECONNREFUSED     ECONNREFUSED
137 #define MP_EHOSTUNREACH     EHOSTUNREACH
138 #define MP_EALREADY         EALREADY
139 #define MP_EINPROGRESS      EINPROGRESS
140 #define MP_ECANCELED        ECANCELED
141 
142 #endif
143 
144 #if MICROPY_PY_UERRNO
145 
146 #include "py/obj.h"
147 
148 qstr mp_errno_to_str(mp_obj_t errno_val);
149 
150 #endif
151 
152 #endif // MICROPY_INCLUDED_PY_MPERRNO_H
153