| 1 | /* | 
|---|
| 2 | * Copyright (c) 2011 Jiri Zarevucky | 
|---|
| 3 | * All rights reserved. | 
|---|
| 4 | * | 
|---|
| 5 | * Redistribution and use in source and binary forms, with or without | 
|---|
| 6 | * modification, are permitted provided that the following conditions | 
|---|
| 7 | * are met: | 
|---|
| 8 | * | 
|---|
| 9 | * - Redistributions of source code must retain the above copyright | 
|---|
| 10 | *   notice, this list of conditions and the following disclaimer. | 
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright | 
|---|
| 12 | *   notice, this list of conditions and the following disclaimer in the | 
|---|
| 13 | *   documentation and/or other materials provided with the distribution. | 
|---|
| 14 | * - The name of the author may not be used to endorse or promote products | 
|---|
| 15 | *   derived from this software without specific prior written permission. | 
|---|
| 16 | * | 
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | 
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|---|
| 27 | */ | 
|---|
| 28 |  | 
|---|
| 29 | /** @addtogroup libposix | 
|---|
| 30 | * @{ | 
|---|
| 31 | */ | 
|---|
| 32 | /** @file System error numbers. | 
|---|
| 33 | */ | 
|---|
| 34 |  | 
|---|
| 35 | #ifndef POSIX_ERRNO_H_ | 
|---|
| 36 | #define POSIX_ERRNO_H_ | 
|---|
| 37 |  | 
|---|
| 38 | #include "libc/errno.h" | 
|---|
| 39 |  | 
|---|
| 40 | /* IMPORTANT: | 
|---|
| 41 | * Since libc uses negative errorcodes, some sort of conversion is necessary to | 
|---|
| 42 | * keep POSIX programs and libraries from breaking. This file maps POSIX error | 
|---|
| 43 | * codes to absolute values of corresponding libc codes where available, and | 
|---|
| 44 | * assigns new code where there is no prior definition in libc. | 
|---|
| 45 | * | 
|---|
| 46 | * A new errno variable is defined. When accessed, the function first looks at | 
|---|
| 47 | * libc errno and iff it is != 0, sets the POSIX errno to absolute value of | 
|---|
| 48 | * libc errno. Given that no library function sets errno to 0 and that all | 
|---|
| 49 | * POSIX libraries will be used solely by POSIX programs (thus, there only needs | 
|---|
| 50 | * to be one way correspondence between errno and posix_errno), this approach | 
|---|
| 51 | * should work as expected in most cases and does not require any wrappers for | 
|---|
| 52 | * libc routines that would just change errno values. | 
|---|
| 53 | * | 
|---|
| 54 | * There is no conditioning by LIBPOSIX_INTERNAL for redefinitions of macros. | 
|---|
| 55 | * If there is a need to check errno for a value not defined by POSIX, it's | 
|---|
| 56 | * necessary to compare errno against abs(ECODE), because there is no | 
|---|
| 57 | * redefinition for such error codes. | 
|---|
| 58 | * | 
|---|
| 59 | * XXX: maybe all HOS error codes should be redefined | 
|---|
| 60 | * | 
|---|
| 61 | * NOTE: This redefinition is slightly POSIX incompatible, since the | 
|---|
| 62 | *  specification requires the macro values to be usable in preprocessing | 
|---|
| 63 | *  directives. I don't think that's very important, though. | 
|---|
| 64 | */ | 
|---|
| 65 |  | 
|---|
| 66 | #undef errno | 
|---|
| 67 | #define errno (*__posix_errno()) | 
|---|
| 68 |  | 
|---|
| 69 | extern int *__posix_errno(void); | 
|---|
| 70 |  | 
|---|
| 71 | #define __TOP_ERRNO (-NO_DATA) | 
|---|
| 72 |  | 
|---|
| 73 | enum { | 
|---|
| 74 | POSIX_E2BIG = __TOP_ERRNO + 1, | 
|---|
| 75 | POSIX_EACCES = __TOP_ERRNO + 2, | 
|---|
| 76 | POSIX_EADDRINUSE = -EADDRINUSE, | 
|---|
| 77 | POSIX_EADDRNOTAVAIL = -EADDRNOTAVAIL, | 
|---|
| 78 | POSIX_EAFNOSUPPORT = -EAFNOSUPPORT, | 
|---|
| 79 | POSIX_EAGAIN = -EAGAIN, | 
|---|
| 80 | POSIX_EALREADY = __TOP_ERRNO + 3, | 
|---|
| 81 | POSIX_EBADF = -EBADF, | 
|---|
| 82 | POSIX_EBADMSG = __TOP_ERRNO + 4, | 
|---|
| 83 | POSIX_EBUSY = -EBUSY, | 
|---|
| 84 | POSIX_ECANCELED = __TOP_ERRNO + 5, | 
|---|
| 85 | POSIX_ECHILD = __TOP_ERRNO + 6, | 
|---|
| 86 | POSIX_ECONNABORTED = __TOP_ERRNO + 7, | 
|---|
| 87 | POSIX_ECONNREFUSED = __TOP_ERRNO + 8, | 
|---|
| 88 | POSIX_ECONNRESET = __TOP_ERRNO + 9, | 
|---|
| 89 | POSIX_EDEADLK = __TOP_ERRNO + 10, | 
|---|
| 90 | POSIX_EDESTADDRREQ = -EDESTADDRREQ, | 
|---|
| 91 | POSIX_EDOM = __TOP_ERRNO + 11, | 
|---|
| 92 | POSIX_EDQUOT = __TOP_ERRNO + 12, | 
|---|
| 93 | POSIX_EEXIST = -EEXIST, | 
|---|
| 94 | POSIX_EFAULT = __TOP_ERRNO + 13, | 
|---|
| 95 | POSIX_EFBIG = __TOP_ERRNO + 14, | 
|---|
| 96 | POSIX_EHOSTUNREACH = __TOP_ERRNO + 15, | 
|---|
| 97 | POSIX_EIDRM = __TOP_ERRNO + 16, | 
|---|
| 98 | POSIX_EILSEQ = __TOP_ERRNO + 17, | 
|---|
| 99 | POSIX_EINPROGRESS = -EINPROGRESS, | 
|---|
| 100 | POSIX_EINTR = -EINTR, | 
|---|
| 101 | POSIX_EINVAL = -EINVAL, | 
|---|
| 102 | POSIX_EIO = -EIO, | 
|---|
| 103 | POSIX_EISCONN = __TOP_ERRNO + 18, | 
|---|
| 104 | POSIX_EISDIR = -EISDIR, | 
|---|
| 105 | POSIX_ELOOP = __TOP_ERRNO + 19, | 
|---|
| 106 | POSIX_EMFILE = -EMFILE, | 
|---|
| 107 | POSIX_EMLINK = -EMLINK, | 
|---|
| 108 | POSIX_EMSGSIZE = __TOP_ERRNO + 20, | 
|---|
| 109 | POSIX_EMULTIHOP = __TOP_ERRNO + 21, | 
|---|
| 110 | POSIX_ENAMETOOLONG = -ENAMETOOLONG, | 
|---|
| 111 | POSIX_ENETDOWN = __TOP_ERRNO + 22, | 
|---|
| 112 | POSIX_ENETRESET = __TOP_ERRNO + 23, | 
|---|
| 113 | POSIX_ENETUNREACH = __TOP_ERRNO + 24, | 
|---|
| 114 | POSIX_ENFILE = __TOP_ERRNO + 25, | 
|---|
| 115 | POSIX_ENOBUFS = __TOP_ERRNO + 26, | 
|---|
| 116 | POSIX_ENODATA = -NO_DATA, | 
|---|
| 117 | POSIX_ENODEV = __TOP_ERRNO + 27, | 
|---|
| 118 | POSIX_ENOENT = -ENOENT, | 
|---|
| 119 | POSIX_ENOEXEC = __TOP_ERRNO + 28, | 
|---|
| 120 | POSIX_ENOLCK = __TOP_ERRNO + 29, | 
|---|
| 121 | POSIX_ENOLINK = __TOP_ERRNO + 30, | 
|---|
| 122 | POSIX_ENOMEM = -ENOMEM, | 
|---|
| 123 | POSIX_ENOMSG = __TOP_ERRNO + 31, | 
|---|
| 124 | POSIX_ENOPROTOOPT = __TOP_ERRNO + 32, | 
|---|
| 125 | POSIX_ENOSPC = -ENOSPC, | 
|---|
| 126 | POSIX_ENOSR = __TOP_ERRNO + 33, | 
|---|
| 127 | POSIX_ENOSTR = __TOP_ERRNO + 34, | 
|---|
| 128 | POSIX_ENOSYS = __TOP_ERRNO + 35, | 
|---|
| 129 | POSIX_ENOTCONN = -ENOTCONN, | 
|---|
| 130 | POSIX_ENOTDIR = -ENOTDIR, | 
|---|
| 131 | POSIX_ENOTEMPTY = -ENOTEMPTY, | 
|---|
| 132 | POSIX_ENOTRECOVERABLE = __TOP_ERRNO + 36, | 
|---|
| 133 | POSIX_ENOTSOCK = -ENOTSOCK, | 
|---|
| 134 | POSIX_ENOTSUP = -ENOTSUP, | 
|---|
| 135 | POSIX_ENOTTY = __TOP_ERRNO + 37, | 
|---|
| 136 | POSIX_ENXIO = __TOP_ERRNO + 38, | 
|---|
| 137 | POSIX_EOPNOTSUPP = __TOP_ERRNO + 39, | 
|---|
| 138 | POSIX_EOVERFLOW = -EOVERFLOW, | 
|---|
| 139 | POSIX_EOWNERDEAD = __TOP_ERRNO + 40, | 
|---|
| 140 | POSIX_EPERM = -EPERM, | 
|---|
| 141 | POSIX_EPIPE = __TOP_ERRNO + 41, | 
|---|
| 142 | POSIX_EPROTO = __TOP_ERRNO + 42, | 
|---|
| 143 | POSIX_EPROTONOSUPPORT = -EPROTONOSUPPORT, | 
|---|
| 144 | POSIX_EPROTOTYPE = __TOP_ERRNO + 43, | 
|---|
| 145 | POSIX_ERANGE = -ERANGE, | 
|---|
| 146 | POSIX_EROFS = __TOP_ERRNO + 44, | 
|---|
| 147 | POSIX_ESPIPE = __TOP_ERRNO + 45, | 
|---|
| 148 | POSIX_ESRCH = __TOP_ERRNO + 46, | 
|---|
| 149 | POSIX_ESTALE = __TOP_ERRNO + 47, | 
|---|
| 150 | POSIX_ETIME = __TOP_ERRNO + 48, | 
|---|
| 151 | POSIX_ETIMEDOUT = __TOP_ERRNO + 49, | 
|---|
| 152 | POSIX_ETXTBSY = __TOP_ERRNO + 50, | 
|---|
| 153 | POSIX_EWOULDBLOCK = __TOP_ERRNO + 51, | 
|---|
| 154 | POSIX_EXDEV = -EXDEV, | 
|---|
| 155 | }; | 
|---|
| 156 |  | 
|---|
| 157 | #undef __TOP_ERRNO | 
|---|
| 158 |  | 
|---|
| 159 | #undef E2BIG | 
|---|
| 160 | #undef EACCES | 
|---|
| 161 | #undef EADDRINUSE | 
|---|
| 162 | #undef EADDRNOTAVAIL | 
|---|
| 163 | #undef EAFNOSUPPORT | 
|---|
| 164 | #undef EAGAIN | 
|---|
| 165 | #undef EALREADY | 
|---|
| 166 | #undef EBADF | 
|---|
| 167 | #undef EBADMSG | 
|---|
| 168 | #undef EBUSY | 
|---|
| 169 | #undef ECANCELED | 
|---|
| 170 | #undef ECHILD | 
|---|
| 171 | #undef ECONNABORTED | 
|---|
| 172 | #undef ECONNREFUSED | 
|---|
| 173 | #undef ECONNRESET | 
|---|
| 174 | #undef EDEADLK | 
|---|
| 175 | #undef EDESTADDRREQ | 
|---|
| 176 | #undef EDOM | 
|---|
| 177 | #undef EDQUOT | 
|---|
| 178 | #undef EEXIST | 
|---|
| 179 | #undef EFAULT | 
|---|
| 180 | #undef EFBIG | 
|---|
| 181 | #undef EHOSTUNREACH | 
|---|
| 182 | #undef EIDRM | 
|---|
| 183 | #undef EILSEQ | 
|---|
| 184 | #undef EINPROGRESS | 
|---|
| 185 | #undef EINTR | 
|---|
| 186 | #undef EINVAL | 
|---|
| 187 | #undef EIO | 
|---|
| 188 | #undef EISCONN | 
|---|
| 189 | #undef EISDIR | 
|---|
| 190 | #undef ELOOP | 
|---|
| 191 | #undef EMFILE | 
|---|
| 192 | #undef EMLINK | 
|---|
| 193 | #undef EMSGSIZE | 
|---|
| 194 | #undef EMULTIHOP | 
|---|
| 195 | #undef ENAMETOOLONG | 
|---|
| 196 | #undef ENETDOWN | 
|---|
| 197 | #undef ENETRESET | 
|---|
| 198 | #undef ENETUNREACH | 
|---|
| 199 | #undef ENFILE | 
|---|
| 200 | #undef ENOBUFS | 
|---|
| 201 | #undef ENODATA | 
|---|
| 202 | #undef ENODEV | 
|---|
| 203 | #undef ENOENT | 
|---|
| 204 | #undef ENOEXEC | 
|---|
| 205 | #undef ENOLCK | 
|---|
| 206 | #undef ENOLINK | 
|---|
| 207 | #undef ENOMEM | 
|---|
| 208 | #undef ENOMSG | 
|---|
| 209 | #undef ENOPROTOOPT | 
|---|
| 210 | #undef ENOSPC | 
|---|
| 211 | #undef ENOSR | 
|---|
| 212 | #undef ENOSTR | 
|---|
| 213 | #undef ENOSYS | 
|---|
| 214 | #undef ENOTCONN | 
|---|
| 215 | #undef ENOTDIR | 
|---|
| 216 | #undef ENOTEMPTY | 
|---|
| 217 | #undef ENOTRECOVERABLE | 
|---|
| 218 | #undef ENOTSOCK | 
|---|
| 219 | #undef ENOTSUP | 
|---|
| 220 | #undef ENOTTY | 
|---|
| 221 | #undef ENXIO | 
|---|
| 222 | #undef EOPNOTSUPP | 
|---|
| 223 | #undef EOVERFLOW | 
|---|
| 224 | #undef EOWNERDEAD | 
|---|
| 225 | #undef EPERM | 
|---|
| 226 | #undef EPIPE | 
|---|
| 227 | #undef EPROTO | 
|---|
| 228 | #undef EPROTONOSUPPORT | 
|---|
| 229 | #undef EPROTOTYPE | 
|---|
| 230 | #undef ERANGE | 
|---|
| 231 | #undef EROFS | 
|---|
| 232 | #undef ESPIPE | 
|---|
| 233 | #undef ESRCH | 
|---|
| 234 | #undef ESTALE | 
|---|
| 235 | #undef ETIME | 
|---|
| 236 | #undef ETIMEDOUT | 
|---|
| 237 | #undef ETXTBSY | 
|---|
| 238 | #undef EWOULDBLOCK | 
|---|
| 239 | #undef EXDEV | 
|---|
| 240 |  | 
|---|
| 241 | #define E2BIG POSIX_E2BIG | 
|---|
| 242 | #define EACCES POSIX_EACCES | 
|---|
| 243 | #define EADDRINUSE POSIX_EADDRINUSE | 
|---|
| 244 | #define EADDRNOTAVAIL POSIX_EADDRNOTAVAIL | 
|---|
| 245 | #define EAFNOSUPPORT POSIX_EAFNOSUPPORT | 
|---|
| 246 | #define EAGAIN POSIX_EAGAIN | 
|---|
| 247 | #define EALREADY POSIX_EALREADY | 
|---|
| 248 | #define EBADF POSIX_EBADF | 
|---|
| 249 | #define EBADMSG POSIX_EBADMSG | 
|---|
| 250 | #define EBUSY POSIX_EBUSY | 
|---|
| 251 | #define ECANCELED POSIX_ECANCELED | 
|---|
| 252 | #define ECHILD POSIX_ECHILD | 
|---|
| 253 | #define ECONNABORTED POSIX_ECONNABORTED | 
|---|
| 254 | #define ECONNREFUSED POSIX_ECONNREFUSED | 
|---|
| 255 | #define ECONNRESET POSIX_ECONNRESET | 
|---|
| 256 | #define EDEADLK POSIX_EDEADLK | 
|---|
| 257 | #define EDESTADDRREQ POSIX_EDESTADDRREQ | 
|---|
| 258 | #define EDOM POSIX_EDOM | 
|---|
| 259 | #define EDQUOT POSIX_EDQUOT | 
|---|
| 260 | #define EEXIST POSIX_EEXIST | 
|---|
| 261 | #define EFAULT POSIX_EFAULT | 
|---|
| 262 | #define EFBIG POSIX_EFBIG | 
|---|
| 263 | #define EHOSTUNREACH POSIX_EHOSTUNREACH | 
|---|
| 264 | #define EIDRM POSIX_EIDRM | 
|---|
| 265 | #define EILSEQ POSIX_EILSEQ | 
|---|
| 266 | #define EINPROGRESS POSIX_EINPROGRESS | 
|---|
| 267 | #define EINTR POSIX_EINTR | 
|---|
| 268 | #define EINVAL POSIX_EINVAL | 
|---|
| 269 | #define EIO POSIX_EIO | 
|---|
| 270 | #define EISCONN POSIX_EISCONN | 
|---|
| 271 | #define EISDIR POSIX_EISDIR | 
|---|
| 272 | #define ELOOP POSIX_ELOOP | 
|---|
| 273 | #define EMFILE POSIX_EMFILE | 
|---|
| 274 | #define EMLINK POSIX_EMLINK | 
|---|
| 275 | #define EMSGSIZE POSIX_EMSGSIZE | 
|---|
| 276 | #define EMULTIHOP POSIX_EMULTIHOP | 
|---|
| 277 | #define ENAMETOOLONG POSIX_ENAMETOOLONG | 
|---|
| 278 | #define ENETDOWN POSIX_ENETDOWN | 
|---|
| 279 | #define ENETRESET POSIX_ENETRESET | 
|---|
| 280 | #define ENETUNREACH POSIX_ENETUNREACH | 
|---|
| 281 | #define ENFILE POSIX_ENFILE | 
|---|
| 282 | #define ENOBUFS POSIX_ENOBUFS | 
|---|
| 283 | #define ENODATA POSIX_ENODATA | 
|---|
| 284 | #define ENODEV POSIX_ENODEV | 
|---|
| 285 | #define ENOENT POSIX_ENOENT | 
|---|
| 286 | #define ENOEXEC POSIX_ENOEXEC | 
|---|
| 287 | #define ENOLCK POSIX_ENOLCK | 
|---|
| 288 | #define ENOLINK POSIX_ENOLINK | 
|---|
| 289 | #define ENOMEM POSIX_ENOMEM | 
|---|
| 290 | #define ENOMSG POSIX_ENOMSG | 
|---|
| 291 | #define ENOPROTOOPT POSIX_ENOPROTOOPT | 
|---|
| 292 | #define ENOSPC POSIX_ENOSPC | 
|---|
| 293 | #define ENOSR POSIX_ENOSR | 
|---|
| 294 | #define ENOSTR POSIX_ENOSTR | 
|---|
| 295 | #define ENOSYS POSIX_ENOSYS | 
|---|
| 296 | #define ENOTCONN POSIX_ENOTCONN | 
|---|
| 297 | #define ENOTDIR POSIX_ENOTDIR | 
|---|
| 298 | #define ENOTEMPTY POSIX_ENOTEMPTY | 
|---|
| 299 | #define ENOTRECOVERABLE POSIX_ENOTRECOVERABLE | 
|---|
| 300 | #define ENOTSOCK POSIX_ENOTSOCK | 
|---|
| 301 | #define ENOTSUP POSIX_ENOTSUP | 
|---|
| 302 | #define ENOTTY POSIX_ENOTTY | 
|---|
| 303 | #define ENXIO POSIX_ENXIO | 
|---|
| 304 | #define EOPNOTSUPP POSIX_EOPNOTSUPP | 
|---|
| 305 | #define EOVERFLOW POSIX_EOVERFLOW | 
|---|
| 306 | #define EOWNERDEAD POSIX_EOWNERDEAD | 
|---|
| 307 | #define EPERM POSIX_EPERM | 
|---|
| 308 | #define EPIPE POSIX_EPIPE | 
|---|
| 309 | #define EPROTO POSIX_EPROTO | 
|---|
| 310 | #define EPROTONOSUPPORT POSIX_EPROTONOSUPPORT | 
|---|
| 311 | #define EPROTOTYPE POSIX_EPROTOTYPE | 
|---|
| 312 | #define ERANGE POSIX_ERANGE | 
|---|
| 313 | #define EROFS POSIX_EROFS | 
|---|
| 314 | #define ESPIPE POSIX_ESPIPE | 
|---|
| 315 | #define ESRCH POSIX_ESRCH | 
|---|
| 316 | #define ESTALE POSIX_ESTALE | 
|---|
| 317 | #define ETIME POSIX_ETIME | 
|---|
| 318 | #define ETIMEDOUT POSIX_ETIMEDOUT | 
|---|
| 319 | #define ETXTBSY POSIX_ETXTBSY | 
|---|
| 320 | #define EWOULDBLOCK POSIX_EWOULDBLOCK | 
|---|
| 321 | #define EXDEV POSIX_EXDEV | 
|---|
| 322 |  | 
|---|
| 323 | #endif /* POSIX_ERRNO_H_ */ | 
|---|
| 324 |  | 
|---|
| 325 | /** @} | 
|---|
| 326 | */ | 
|---|