1 /**
2  * @file errno.h
3  * @copyright Copyright (C) 2015-2018 Alibaba Group Holding Limited
4  */
5 
6 #ifndef AOS_ERRNO_H
7 #define AOS_ERRNO_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /**
14  * @addtogroup aos_errno errno
15  * Define standard errno.
16  *
17  * @{
18  */
19 
20 #if defined(__GNUC__)&&!defined(__CC_ARM)||defined(_WIN32)
21 #include <errno.h>
22 
23 #else
24 /* Define standard errno for __CC_ARM and __ICCARM__ */
25 #define  EPERM         1  /**< Operation not permitted */
26 #define  ENOENT        2  /**< No such file or directory */
27 #define  ESRCH         3  /**< No such process */
28 #define  EINTR         4  /**< Interrupted system call */
29 #define  EIO           5  /**< I/O error */
30 #define  ENXIO         6  /**< No such device or address */
31 #define  E2BIG         7  /**< Arg list too long */
32 #define  ENOEXEC       8  /**< Exec format error */
33 #define  EBADF         9  /**< Bad file number */
34 #define  ECHILD       10  /**< No child processes */
35 #define  EAGAIN       11  /**< Try again */
36 
37 #ifdef   ENOMEM
38 #undef   ENOMEM
39 #endif
40 
41 #define  ENOMEM       12  /**< Out of memory */
42 #define  EACCES       13  /**< Permission denied */
43 #define  EFAULT       14  /**< Bad address */
44 #define  ENOTBLK      15  /**< Block device required */
45 #define  EBUSY        16  /**< Device or resource busy */
46 #define  EEXIST       17  /**< File exists */
47 #define  EXDEV        18  /**< Cross-device link */
48 #define  ENODEV       19  /**< No such device */
49 #define  ENOTDIR      20  /**< Not a directory */
50 #define  EISDIR       21  /**< Is a directory */
51 
52 #ifdef   EINVAL
53 #undef   EINVAL
54 #endif
55 
56 #define  EINVAL       22  /**< Invalid argument */
57 #define  ENFILE       23  /**< File table overflow */
58 #define  EMFILE       24  /**< Too many open files */
59 #define  ENOTTY       25  /**< Not a typewriter */
60 #define  ETXTBSY      26  /**< Text file busy */
61 #define  EFBIG        27  /**< File too large */
62 #define  ENOSPC       28  /**< No space left on device */
63 #define  ESPIPE       29  /**< Illegal seek */
64 #define  EROFS        30  /**< Read-only file system */
65 #define  EMLINK       31  /**< Too many links */
66 #define  EPIPE        32  /**< Broken pipe */
67 
68 #ifdef   EDOM
69 #undef   EDOM
70 #define  EDOM         33  /**< Math argument out of domain of func */
71 #endif
72 
73 #ifdef   ERANGE
74 #undef   ERANGE
75 #define  ERANGE       34  /**< Math result not representable */
76 #endif
77 
78 #define  EDEADLK      35  /**< Resource deadlock would occur */
79 #define  ENAMETOOLONG 36  /**< File name too long */
80 #define  ENOLCK       37  /**< No record locks available */
81 #define  ENOSYS       38  /**< Function not implemented */
82 #define  ENOTEMPTY    39  /**< Directory not empty */
83 #define  ELOOP        40  /**< Too many symbolic links encountered */
84 #define  EWOULDBLOCK  EAGAIN  /**< Operation would block */
85 #define  ENOMSG       42  /**< No message of desired type */
86 #define  EIDRM        43  /**< Identifier removed */
87 #define  ECHRNG       44  /**< Channel number out of range */
88 #define  EL2NSYNC     45  /**<* Level 2 not synchronized */
89 #define  EL3HLT       46  /**< Level 3 halted */
90 #define  EL3RST       47  /**< Level 3 reset */
91 #define  ELNRNG       48  /**< Link number out of range */
92 #define  EUNATCH      49  /**< Protocol driver not attached */
93 #define  ENOCSI       50  /* No CSI structure available */
94 #define  EL2HLT       51  /**< Level 2 halted */
95 #define  EBADE        52  /**< Invalid exchange */
96 #define  EBADR        53  /**< Invalid request descriptor */
97 #define  EXFULL       54  /**< Exchange full */
98 #define  ENOANO       55  /**< No anode */
99 #define  EBADRQC      56  /**< Invalid request code */
100 #define  EBADSLT      57  /**< Invalid slot */
101 
102 #define  EDEADLOCK    EDEADLK
103 
104 #define  EBFONT       59  /**< Bad font file format */
105 #define  ENOSTR       60  /**< Device not a stream */
106 #define  ENODATA      61  /**< No data available */
107 #define  ETIME        62  /**< Timer expired */
108 #define  ENOSR        63  /**< Out of streams resources */
109 #define  ENONET       64  /**< Machine is not on the network */
110 #define  ENOPKG       65  /**< Package not installed */
111 #define  EREMOTE      66  /**< Object is remote */
112 #define  ENOLINK      67  /**< Link has been severed */
113 #define  EADV         68  /**< Advertise error */
114 #define  ESRMNT       69  /**< Srmount error */
115 #define  ECOMM        70  /**< Communication error on send */
116 #define  EPROTO       71  /**< Protocol error */
117 #define  EMULTIHOP    72  /**< Multihop attempted */
118 #define  EDOTDOT      73  /**< RFS specific error */
119 #define  EBADMSG      74  /**< Not a data message */
120 #define  EOVERFLOW    75  /**< Value too large for defined data type */
121 #define  ENOTUNIQ     76  /**< Name not unique on network */
122 #define  EBADFD       77  /**< File descriptor in bad state */
123 #define  EREMCHG      78  /**< Remote address changed */
124 #define  ELIBACC      79  /**< Can not access a needed shared library */
125 #define  ELIBBAD      80  /**< Accessing a corrupted shared library */
126 #define  ELIBSCN      81  /**< .lib section in a.out corrupted */
127 #define  ELIBMAX      82  /**< Attempting to link in too many shared libraries */
128 #define  ELIBEXEC     83  /**< Cannot exec a shared library directly */
129 
130 #ifdef   EILSEQ
131 #undef   EILSEQ
132 #endif
133 
134 #define  EILSEQ       84  /**< Illegal byte sequence */
135 #define  ERESTART     85  /**< Interrupted system call should be restarted */
136 #define  ESTRPIPE     86  /**< Streams pipe error */
137 #define  EUSERS       87  /**< Too many users */
138 #define  ENOTSOCK     88  /**< Socket operation on non-socket */
139 #define  EDESTADDRREQ 89  /**< Destination address required */
140 #define  EMSGSIZE     90  /**< Message too long */
141 #define  EPROTOTYPE   91  /**< Protocol wrong type for socket */
142 #define  ENOPROTOOPT  92  /**< Protocol not available */
143 #define  EPROTONOSUPPORT 93  /**< Protocol not supported */
144 #define  ESOCKTNOSUPPORT 94  /**< Socket type not supported */
145 #define  EOPNOTSUPP      95  /**< Operation not supported on transport endpoint */
146 #define  EPFNOSUPPORT    96  /**< Protocol family not supported */
147 #define  EAFNOSUPPORT    97  /**< Address family not supported by protocol */
148 #define  EADDRINUSE      98  /**< Address already in use */
149 #define  EADDRNOTAVAIL   99  /**< Cannot assign requested address */
150 #define  ENETDOWN       100  /**< Network is down */
151 #define  ENETUNREACH    101  /**< Network is unreachable */
152 #define  ENETRESET      102  /**< Network dropped connection because of reset */
153 #define  ECONNABORTED   103  /**< Software caused connection abort */
154 #define  ECONNRESET     104  /**< Connection reset by peer */
155 #define  ENOBUFS        105  /**<* No buffer space available */
156 #define  EISCONN        106  /**< Transport endpoint is already connected */
157 #define  ENOTCONN       107  /**< Transport endpoint is not connected */
158 #define  ESHUTDOWN      108  /**< Cannot send after transport endpoint shutdown */
159 #define  ETOOMANYREFS   109  /**< Too many references: cannot splice */
160 #define  ETIMEDOUT      110  /**< Connection timed out */
161 #define  ECONNREFUSED   111  /**< Connection refused */
162 #define  EHOSTDOWN      112  /**< Host is down */
163 #define  EHOSTUNREACH   113  /**< No route to host */
164 #define  EALREADY       114  /**< Operation already in progress */
165 #define  EINPROGRESS    115  /**< Operation now in progress */
166 #define  ESTALE         116  /**< Stale NFS file handle */
167 #define  EUCLEAN        117  /**< Structure needs cleaning */
168 #define  ENOTNAM        118  /**< Not a XENIX named type file */
169 #define  ENAVAIL        119  /**< No XENIX semaphores available */
170 #define  EISNAM         120  /**< Is a named type file */
171 #define  EREMOTEIO      121  /**< Remote I/O error */
172 #define  EDQUOT         122  /**< Quota exceeded */
173 
174 #define  ENOMEDIUM      123  /**< No medium found */
175 #define  EMEDIUMTYPE    124  /**< Wrong medium type */
176 
177 
178 #define ENSROK                    0 /**< DNS server returned answer with no data */
179 #define ENSRNODATA              160 /**< DNS server returned answer with no data */
180 #define ENSRFORMERR             161 /**< DNS server claims query was misformatted */
181 #define ENSRSERVFAIL            162 /**< DNS server returned general failure */
182 #define ENSRNOTFOUND            163 /**< Domain name not found */
183 #define ENSRNOTIMP              164 /**< DNS server does not implement requested operation */
184 #define ENSRREFUSED             165 /**< DNS server refused query */
185 #define ENSRBADQUERY            166 /**< Misformatted DNS query */
186 #define ENSRBADNAME             167 /**< Misformatted domain name */
187 #define ENSRBADFAMILY           168 /**< Unsupported address family */
188 #define ENSRBADRESP             169 /**< Misformatted DNS reply */
189 #define ENSRCONNREFUSED         170 /**< Could not contact DNS servers */
190 #define ENSRTIMEOUT             171 /**< Timeout while contacting DNS servers */
191 #define ENSROF                  172 /**< End of file */
192 #define ENSRFILE                173 /**< Error reading file */
193 #define ENSRNOMEM               174 /**< Out of memory */
194 #define ENSRDESTRUCTION         175 /**< Application terminated lookup */
195 #define ENSRQUERYDOMAINTOOLONG  176 /**< Domain name is too long */
196 #define ENSRCNAMELOOP           177 /**< Domain name is too long */
197 
198 #endif /* defined(__GNUC__)&&!defined(__CC_ARM)||defined(_WIN32) */
199 
200 /**
201  * Redefine the errno, Only use in framework/app
202  */
203 #ifdef BUILD_BIN
204 
205 #undef set_errno
206 #define set_errno(err) do { if (err) { errno = (err); } } while(0)
207 
208 #else /* BUILD_BIN */
209 
210 #ifdef BUILD_APP
211 /**
212  * Get system errno.
213  *
214  * @return  int: return system errno for app bin.
215  */
216 extern int  get_errno(void);
217 /**
218  * Set system errno.
219  *
220  * @param[in]  err       err to set into system.
221  *
222  * @return  none.
223  */
224 extern void set_errno(int err);
225 
226 #undef errno
227 #define errno get_errno()   /* Get system errno, unique copy for system */
228 
229 #endif /* BUILD_APP */
230 
231 #endif /* BUILD_BIN */
232 
233 /** @} */
234 
235 #ifdef __cplusplus
236 }
237 #endif
238 
239 #endif /* AOS_ERRNO_H */
240 
241