errno.ha (12988B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 // Represents an error returned from the FreeBSD kernel. 5 export type errno = !int; 6 7 // Checks the return value from a FreeBSD syscall and, if found to be in error, 8 // returns the appropriate error. Otherwise, returns the original value. 9 fn wrap_return(r: u64) (errno | u64) = { 10 if (r > -4096: u64) { 11 return (-(r: i64)): errno; 12 }; 13 return r; 14 }; 15 16 // Obtains a human-friendly reading of an [[errno]] (e.g. "Operation not 17 // permitted"). The return value may be statically allocated. 18 export fn strerror(err: errno) str = { 19 switch (err) { 20 case EPERM => 21 return "Operation not permitted"; 22 case ENOENT => 23 return "No such file or directory"; 24 case ESRCH => 25 return "No such process"; 26 case EINTR => 27 return "Interrupted system call"; 28 case EIO => 29 return "Input/output error"; 30 case ENXIO => 31 return "No such device or address"; 32 case E2BIG => 33 return "Argument list too long"; 34 case ENOEXEC => 35 return "Exec format error"; 36 case EBADF => 37 return "Bad file descriptor"; 38 case ECHILD => 39 return "No child processes"; 40 case EAGAIN => 41 return "Resource temporarily unavailable"; 42 case ENOMEM => 43 return "Cannot allocate memory"; 44 case EACCES => 45 return "Permission denied"; 46 case EFAULT => 47 return "Bad address"; 48 case ENOTBLK => 49 return "Block device required"; 50 case EBUSY => 51 return "Device or resource busy"; 52 case EEXIST => 53 return "File exists"; 54 case EXDEV => 55 return "Invalid cross-device link"; 56 case ENODEV => 57 return "No such device"; 58 case ENOTDIR => 59 return "Not a directory"; 60 case EISDIR => 61 return "Is a directory"; 62 case EINVAL => 63 return "Invalid argument"; 64 case ENFILE => 65 return "Too many open files in system"; 66 case EMFILE => 67 return "Too many open files"; 68 case ENOTTY => 69 return "Inappropriate ioctl for device"; 70 case ETXTBSY => 71 return "Text file busy"; 72 case EFBIG => 73 return "File too large"; 74 case ENOSPC => 75 return "No space left on device"; 76 case ESPIPE => 77 return "Illegal seek"; 78 case EROFS => 79 return "Read-only file system"; 80 case EMLINK => 81 return "Too many links"; 82 case EPIPE => 83 return "Broken pipe"; 84 case EDOM => 85 return "Numerical argument out of domain"; 86 case ERANGE => 87 return "Numerical result out of range"; 88 case EDEADLK => 89 return "Resource deadlock avoided"; 90 case ENAMETOOLONG => 91 return "File name too long"; 92 case ENOLCK => 93 return "No locks available"; 94 case ENOSYS => 95 return "Function not implemented"; 96 case ENOTEMPTY => 97 return "Directory not empty"; 98 case ELOOP => 99 return "Too many levels of symbolic links"; 100 case ENOMSG => 101 return "No message of desired type"; 102 case EIDRM => 103 return "Identifier removed"; 104 case EREMOTE => 105 return "Object is remote"; 106 case ENOLINK => 107 return "Link has been severed"; 108 case EPROTO => 109 return "Protocol error"; 110 case EMULTIHOP => 111 return "Multihop attempted"; 112 case EBADMSG => 113 return "Bad message"; 114 case EOVERFLOW => 115 return "Value too large for defined data type"; 116 case EILSEQ => 117 return "Invalid or incomplete multibyte or wide character"; 118 case EUSERS => 119 return "Too many users"; 120 case ENOTSOCK => 121 return "Socket operation on non-socket"; 122 case EDESTADDRREQ => 123 return "Destination address required"; 124 case EMSGSIZE => 125 return "Message too long"; 126 case EPROTOTYPE => 127 return "Protocol wrong type for socket"; 128 case ENOPROTOOPT => 129 return "Protocol not available"; 130 case EPROTONOSUPPORT => 131 return "Protocol not supported"; 132 case ESOCKTNOSUPPORT => 133 return "Socket type not supported"; 134 case EOPNOTSUPP => 135 return "Operation not supported"; 136 case EPFNOSUPPORT => 137 return "Protocol family not supported"; 138 case EAFNOSUPPORT => 139 return "Address family not supported by protocol"; 140 case EADDRINUSE => 141 return "Address already in use"; 142 case EADDRNOTAVAIL => 143 return "Cannot assign requested address"; 144 case ENETDOWN => 145 return "Network is down"; 146 case ENETUNREACH => 147 return "Network is unreachable"; 148 case ENETRESET => 149 return "Network dropped connection on reset"; 150 case ECONNABORTED => 151 return "Software caused connection abort"; 152 case ECONNRESET => 153 return "Connection reset by peer"; 154 case ENOBUFS => 155 return "No buffer space available"; 156 case EISCONN => 157 return "Transport endpoint is already connected"; 158 case ENOTCONN => 159 return "Transport endpoint is not connected"; 160 case ESHUTDOWN => 161 return "Cannot send after transport endpoint shutdown"; 162 case ETOOMANYREFS => 163 return "Too many references: cannot splice"; 164 case ETIMEDOUT => 165 return "Connection timed out"; 166 case ECONNREFUSED => 167 return "Connection refused"; 168 case EHOSTDOWN => 169 return "Host is down"; 170 case EHOSTUNREACH => 171 return "No route to host"; 172 case EALREADY => 173 return "Operation already in progress"; 174 case EINPROGRESS => 175 return "Operation now in progress"; 176 case ESTALE => 177 return "Stale file handle"; 178 case EDQUOT => 179 return "Disk quota exceeded"; 180 case ECANCELED => 181 return "Operation canceled"; 182 case EOWNERDEAD => 183 return "Owner died"; 184 case ENOTRECOVERABLE => 185 return "State not recoverable"; 186 case EAUTH => 187 return "Authentication error"; 188 case EBADRPC => 189 return "RPC struct is bad"; 190 case ECAPMODE => 191 return "Not permitted in capability mode"; 192 case EDOOFUS => 193 return "Programming error"; 194 case EINTEGRITY => 195 return "Integrity check failed"; 196 case ENEEDAUTH => 197 return "Need authenticator"; 198 case ENOATTR => 199 return "Attribute not found"; 200 case ENOTCAPABLE => 201 return "Capabilities insufficient"; 202 case EPROCLIM => 203 return "Too many processes"; 204 case EPROCUNAVAIL => 205 return "Bad procedure for program"; 206 case EPROGMISMATCH => 207 return "Program version wrong"; 208 case EPROGUNAVAIL => 209 return "RPC program not available"; 210 case ERPCMISMATCH => 211 return "RPC version wrong"; 212 case => 213 return unknown_errno(err); 214 }; 215 }; 216 217 // Gets the programmer-friendly name for an [[errno]] (e.g. EPERM). The return 218 // value may be statically allocated. 219 export fn errname(err: errno) str = { 220 switch (err) { 221 case EPERM => 222 return "EPERM"; 223 case ENOENT => 224 return "ENOENT"; 225 case ESRCH => 226 return "ESRCH"; 227 case EINTR => 228 return "EINTR"; 229 case EIO => 230 return "EIO"; 231 case ENXIO => 232 return "ENXIO"; 233 case E2BIG => 234 return "E2BIG"; 235 case ENOEXEC => 236 return "ENOEXEC"; 237 case EBADF => 238 return "EBADF"; 239 case ECHILD => 240 return "ECHILD"; 241 case EAGAIN => 242 return "EAGAIN"; 243 case ENOMEM => 244 return "ENOMEM"; 245 case EACCES => 246 return "EACCES"; 247 case EFAULT => 248 return "EFAULT"; 249 case ENOTBLK => 250 return "ENOTBLK"; 251 case EBUSY => 252 return "EBUSY"; 253 case EEXIST => 254 return "EEXIST"; 255 case EXDEV => 256 return "EXDEV"; 257 case ENODEV => 258 return "ENODEV"; 259 case ENOTDIR => 260 return "ENOTDIR"; 261 case EISDIR => 262 return "EISDIR"; 263 case EINVAL => 264 return "EINVAL"; 265 case ENFILE => 266 return "ENFILE"; 267 case EMFILE => 268 return "EMFILE"; 269 case ENOTTY => 270 return "ENOTTY"; 271 case ETXTBSY => 272 return "ETXTBSY"; 273 case EFBIG => 274 return "EFBIG"; 275 case ENOSPC => 276 return "ENOSPC"; 277 case ESPIPE => 278 return "ESPIPE"; 279 case EROFS => 280 return "EROFS"; 281 case EMLINK => 282 return "EMLINK"; 283 case EPIPE => 284 return "EPIPE"; 285 case EDOM => 286 return "EDOM"; 287 case ERANGE => 288 return "ERANGE"; 289 case EDEADLK => 290 return "EDEADLK"; 291 case ENAMETOOLONG => 292 return "ENAMETOOLONG"; 293 case ENOLCK => 294 return "ENOLCK"; 295 case ENOSYS => 296 return "ENOSYS"; 297 case ENOTEMPTY => 298 return "ENOTEMPTY"; 299 case ELOOP => 300 return "ELOOP"; 301 case ENOMSG => 302 return "ENOMSG"; 303 case EIDRM => 304 return "EIDRM"; 305 case EREMOTE => 306 return "EREMOTE"; 307 case ENOLINK => 308 return "ENOLINK"; 309 case EPROTO => 310 return "EPROTO"; 311 case EMULTIHOP => 312 return "EMULTIHOP"; 313 case EBADMSG => 314 return "EBADMSG"; 315 case EOVERFLOW => 316 return "EOVERFLOW"; 317 case EILSEQ => 318 return "EILSEQ"; 319 case EUSERS => 320 return "EUSERS"; 321 case ENOTSOCK => 322 return "ENOTSOCK"; 323 case EDESTADDRREQ => 324 return "EDESTADDRREQ"; 325 case EMSGSIZE => 326 return "EMSGSIZE"; 327 case EPROTOTYPE => 328 return "EPROTOTYPE"; 329 case ENOPROTOOPT => 330 return "ENOPROTOOPT"; 331 case EPROTONOSUPPORT => 332 return "EPROTONOSUPPORT"; 333 case ESOCKTNOSUPPORT => 334 return "ESOCKTNOSUPPORT"; 335 case EOPNOTSUPP => 336 return "EOPNOTSUPP"; 337 case EPFNOSUPPORT => 338 return "EPFNOSUPPORT"; 339 case EAFNOSUPPORT => 340 return "EAFNOSUPPORT"; 341 case EADDRINUSE => 342 return "EADDRINUSE"; 343 case EADDRNOTAVAIL => 344 return "EADDRNOTAVAIL"; 345 case ENETDOWN => 346 return "ENETDOWN"; 347 case ENETUNREACH => 348 return "ENETUNREACH"; 349 case ENETRESET => 350 return "ENETRESET"; 351 case ECONNABORTED => 352 return "ECONNABORTED"; 353 case ECONNRESET => 354 return "ECONNRESET"; 355 case ENOBUFS => 356 return "ENOBUFS"; 357 case EISCONN => 358 return "EISCONN"; 359 case ENOTCONN => 360 return "ENOTCONN"; 361 case ESHUTDOWN => 362 return "ESHUTDOWN"; 363 case ETOOMANYREFS => 364 return "ETOOMANYREFS"; 365 case ETIMEDOUT => 366 return "ETIMEDOUT"; 367 case ECONNREFUSED => 368 return "ECONNREFUSED"; 369 case EHOSTDOWN => 370 return "EHOSTDOWN"; 371 case EHOSTUNREACH => 372 return "EHOSTUNREACH"; 373 case EALREADY => 374 return "EALREADY"; 375 case EINPROGRESS => 376 return "EINPROGRESS"; 377 case ESTALE => 378 return "ESTALE"; 379 case EDQUOT => 380 return "EDQUOT"; 381 case ECANCELED => 382 return "ECANCELED"; 383 case EOWNERDEAD => 384 return "EOWNERDEAD"; 385 case ENOTRECOVERABLE => 386 return "ENOTRECOVERABLE"; 387 case EAUTH => 388 return "EAUTH"; 389 case EBADRPC => 390 return "EBADRPC"; 391 case ECAPMODE => 392 return "ECAPMODE"; 393 case EDOOFUS => 394 return "EDOOFUS"; 395 case EINTEGRITY => 396 return "EINTEGRITY"; 397 case ENEEDAUTH => 398 return "ENEEDAUTH"; 399 case ENOATTR => 400 return "ENOATTR"; 401 case ENOTCAPABLE => 402 return "ENOTCAPABLE"; 403 case EPROCLIM => 404 return "EPROCLIM"; 405 case EPROCUNAVAIL => 406 return "EPROCUNAVAIL"; 407 case EPROGMISMATCH => 408 return "EPROGMISMATCH"; 409 case EPROGUNAVAIL => 410 return "EPROGUNAVAIL"; 411 case ERPCMISMATCH => 412 return "ERPCMISMATCH"; 413 case => 414 return unknown_errno(err); 415 }; 416 }; 417 418 export def EPERM: errno = 1; 419 export def ENOENT: errno = 2; 420 export def ESRCH: errno = 3; 421 export def EINTR: errno = 4; 422 export def EIO: errno = 5; 423 export def ENXIO: errno = 6; 424 export def E2BIG: errno = 7; 425 export def ENOEXEC: errno = 8; 426 export def EBADF: errno = 9; 427 export def ECHILD: errno = 10; 428 export def EDEADLK: errno = 11; 429 export def ENOMEM: errno = 12; 430 export def EACCES: errno = 13; 431 export def EFAULT: errno = 14; 432 export def ENOTBLK: errno = 15; 433 export def EBUSY: errno = 16; 434 export def EEXIST: errno = 17; 435 export def EXDEV: errno = 18; 436 export def ENODEV: errno = 19; 437 export def ENOTDIR: errno = 20; 438 export def EISDIR: errno = 21; 439 export def EINVAL: errno = 22; 440 export def ENFILE: errno = 23; 441 export def EMFILE: errno = 24; 442 export def ENOTTY: errno = 25; 443 export def ETXTBSY: errno = 26; 444 export def EFBIG: errno = 27; 445 export def ENOSPC: errno = 28; 446 export def ESPIPE: errno = 29; 447 export def EROFS: errno = 30; 448 export def EMLINK: errno = 31; 449 export def EPIPE: errno = 32; 450 export def EDOM: errno = 33; 451 export def ERANGE: errno = 34; 452 export def EAGAIN: errno = 35; 453 export def EWOULDBLOCK: errno = EAGAIN; 454 export def EINPROGRESS: errno = 36; 455 export def EALREADY: errno = 37; 456 export def ENOTSOCK: errno = 38; 457 export def EDESTADDRREQ: errno = 39; 458 export def EMSGSIZE: errno = 40; 459 export def EPROTOTYPE: errno = 41; 460 export def ENOPROTOOPT: errno = 42; 461 export def EPROTONOSUPPORT: errno = 43; 462 export def ESOCKTNOSUPPORT: errno = 44; 463 export def EOPNOTSUPP: errno = 45; 464 export def ENOTSUP: errno = EOPNOTSUPP; 465 export def EPFNOSUPPORT: errno = 46; 466 export def EAFNOSUPPORT: errno = 47; 467 export def EADDRINUSE: errno = 48; 468 export def EADDRNOTAVAIL: errno = 49; 469 export def ENETDOWN: errno = 50; 470 export def ENETUNREACH: errno = 51; 471 export def ENETRESET: errno = 52; 472 export def ECONNABORTED: errno = 53; 473 export def ECONNRESET: errno = 54; 474 export def ENOBUFS: errno = 55; 475 export def EISCONN: errno = 56; 476 export def ENOTCONN: errno = 57; 477 export def ESHUTDOWN: errno = 58; 478 export def ETOOMANYREFS: errno = 59; 479 export def ETIMEDOUT: errno = 60; 480 export def ECONNREFUSED: errno = 61; 481 export def ELOOP: errno = 62; 482 export def ENAMETOOLONG: errno = 63; 483 export def EHOSTDOWN: errno = 64; 484 export def EHOSTUNREACH: errno = 65; 485 export def ENOTEMPTY: errno = 66; 486 export def EPROCLIM: errno = 67; 487 export def EUSERS: errno = 68; 488 export def EDQUOT: errno = 69; 489 export def ESTALE: errno = 70; 490 export def EREMOTE: errno = 71; 491 export def EBADRPC: errno = 72; 492 export def ERPCMISMATCH: errno = 73; 493 export def EPROGUNAVAIL: errno = 74; 494 export def EPROGMISMATCH: errno = 75; 495 export def EPROCUNAVAIL: errno = 76; 496 export def ENOLCK: errno = 77; 497 export def ENOSYS: errno = 78; 498 export def EFTYPE: errno = 79; 499 export def EAUTH: errno = 80; 500 export def ENEEDAUTH: errno = 81; 501 export def EIDRM: errno = 82; 502 export def ENOMSG: errno = 83; 503 export def EOVERFLOW: errno = 84; 504 export def ECANCELED: errno = 85; 505 export def EILSEQ: errno = 86; 506 export def ENOATTR: errno = 87; 507 export def EDOOFUS: errno = 88; 508 export def EBADMSG: errno = 89; 509 export def EMULTIHOP: errno = 90; 510 export def ENOLINK: errno = 91; 511 export def EPROTO: errno = 92; 512 export def ENOTCAPABLE: errno = 93; 513 export def ECAPMODE: errno = 94; 514 export def ENOTRECOVERABLE: errno = 95; 515 export def EOWNERDEAD: errno = 96; 516 export def EINTEGRITY: errno = 97;