errno.ha (17313B)
1 // SPDX-License-Identifier: MPL-2.0 2 // (c) Hare authors <https://harelang.org> 3 4 // Represents an error returned from the Linux kernel. 5 export type errno = !int; 6 7 // Checks the return value from a Linux 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 ECHRNG => 105 return "Channel number out of range"; 106 case EL2NSYNC => 107 return "Level 2 not synchronized"; 108 case EL3HLT => 109 return "Level 3 halted"; 110 case EL3RST => 111 return "Level 3 reset"; 112 case ELNRNG => 113 return "Link number out of range"; 114 case EUNATCH => 115 return "Protocol driver not attached"; 116 case ENOCSI => 117 return "No CSI structure available"; 118 case EL2HLT => 119 return "Level 2 halted"; 120 case EBADE => 121 return "Invalid exchange"; 122 case EBADR => 123 return "Invalid request descriptor"; 124 case EXFULL => 125 return "Exchange full"; 126 case ENOANO => 127 return "No anode"; 128 case EBADRQC => 129 return "Invalid request code"; 130 case EBADSLT => 131 return "Invalid slot"; 132 case EBFONT => 133 return "Bad font file format"; 134 case ENOSTR => 135 return "Device not a stream"; 136 case ENODATA => 137 return "No data available"; 138 case ETIME => 139 return "Timer expired"; 140 case ENOSR => 141 return "Out of streams resources"; 142 case ENONET => 143 return "Machine is not on the network"; 144 case ENOPKG => 145 return "Package not installed"; 146 case EREMOTE => 147 return "Object is remote"; 148 case ENOLINK => 149 return "Link has been severed"; 150 case EADV => 151 return "Advertise error"; 152 case ESRMNT => 153 return "Srmount error"; 154 case ECOMM => 155 return "Communication error on send"; 156 case EPROTO => 157 return "Protocol error"; 158 case EMULTIHOP => 159 return "Multihop attempted"; 160 case EDOTDOT => 161 return "RFS specific error"; 162 case EBADMSG => 163 return "Bad message"; 164 case EOVERFLOW => 165 return "Value too large for defined data type"; 166 case ENOTUNIQ => 167 return "Name not unique on network"; 168 case EBADFD => 169 return "File descriptor in bad state"; 170 case EREMCHG => 171 return "Remote address changed"; 172 case ELIBACC => 173 return "Can not access a needed shared library"; 174 case ELIBBAD => 175 return "Accessing a corrupted shared library"; 176 case ELIBSCN => 177 return ".lib section in a.out corrupted"; 178 case ELIBMAX => 179 return "Attempting to link in too many shared libraries"; 180 case ELIBEXEC => 181 return "Cannot exec a shared library directly"; 182 case EILSEQ => 183 return "Invalid or incomplete multibyte or wide character"; 184 case ERESTART => 185 return "Interrupted system call should be restarted"; 186 case ESTRPIPE => 187 return "Streams pipe error"; 188 case EUSERS => 189 return "Too many users"; 190 case ENOTSOCK => 191 return "Socket operation on non-socket"; 192 case EDESTADDRREQ => 193 return "Destination address required"; 194 case EMSGSIZE => 195 return "Message too long"; 196 case EPROTOTYPE => 197 return "Protocol wrong type for socket"; 198 case ENOPROTOOPT => 199 return "Protocol not available"; 200 case EPROTONOSUPPORT => 201 return "Protocol not supported"; 202 case ESOCKTNOSUPPORT => 203 return "Socket type not supported"; 204 case EOPNOTSUPP => 205 return "Operation not supported"; 206 case EPFNOSUPPORT => 207 return "Protocol family not supported"; 208 case EAFNOSUPPORT => 209 return "Address family not supported by protocol"; 210 case EADDRINUSE => 211 return "Address already in use"; 212 case EADDRNOTAVAIL => 213 return "Cannot assign requested address"; 214 case ENETDOWN => 215 return "Network is down"; 216 case ENETUNREACH => 217 return "Network is unreachable"; 218 case ENETRESET => 219 return "Network dropped connection on reset"; 220 case ECONNABORTED => 221 return "Software caused connection abort"; 222 case ECONNRESET => 223 return "Connection reset by peer"; 224 case ENOBUFS => 225 return "No buffer space available"; 226 case EISCONN => 227 return "Transport endpoint is already connected"; 228 case ENOTCONN => 229 return "Transport endpoint is not connected"; 230 case ESHUTDOWN => 231 return "Cannot send after transport endpoint shutdown"; 232 case ETOOMANYREFS => 233 return "Too many references: cannot splice"; 234 case ETIMEDOUT => 235 return "Connection timed out"; 236 case ECONNREFUSED => 237 return "Connection refused"; 238 case EHOSTDOWN => 239 return "Host is down"; 240 case EHOSTUNREACH => 241 return "No route to host"; 242 case EALREADY => 243 return "Operation already in progress"; 244 case EINPROGRESS => 245 return "Operation now in progress"; 246 case ESTALE => 247 return "Stale file handle"; 248 case EUCLEAN => 249 return "Structure needs cleaning"; 250 case ENOTNAM => 251 return "Not a XENIX named type file"; 252 case ENAVAIL => 253 return "No XENIX semaphores available"; 254 case EISNAM => 255 return "Is a named type file"; 256 case EREMOTEIO => 257 return "Remote I/O error"; 258 case EDQUOT => 259 return "Disk quota exceeded"; 260 case ENOMEDIUM => 261 return "No medium found"; 262 case EMEDIUMTYPE => 263 return "Wrong medium type"; 264 case ECANCELED => 265 return "Operation canceled"; 266 case ENOKEY => 267 return "Required key not available"; 268 case EKEYEXPIRED => 269 return "Key has expired"; 270 case EKEYREVOKED => 271 return "Key has been revoked"; 272 case EKEYREJECTED => 273 return "Key was rejected by service"; 274 case EOWNERDEAD => 275 return "Owner died"; 276 case ENOTRECOVERABLE => 277 return "State not recoverable"; 278 case ERFKILL => 279 return "Operation not possible due to RF-kill"; 280 case EHWPOISON => 281 return "Memory page has hardware error"; 282 case => 283 return unknown_errno(err); 284 }; 285 }; 286 287 // Gets the programmer-friendly name for an [[errno]] (e.g. EPERM). The return 288 // value may be statically allocated. 289 export fn errname(err: errno) str = { 290 switch (err) { 291 case EPERM => 292 return "EPERM"; 293 case ENOENT => 294 return "ENOENT"; 295 case ESRCH => 296 return "ESRCH"; 297 case EINTR => 298 return "EINTR"; 299 case EIO => 300 return "EIO"; 301 case ENXIO => 302 return "ENXIO"; 303 case E2BIG => 304 return "E2BIG"; 305 case ENOEXEC => 306 return "ENOEXEC"; 307 case EBADF => 308 return "EBADF"; 309 case ECHILD => 310 return "ECHILD"; 311 case EAGAIN => 312 return "EAGAIN"; 313 case ENOMEM => 314 return "ENOMEM"; 315 case EACCES => 316 return "EACCES"; 317 case EFAULT => 318 return "EFAULT"; 319 case ENOTBLK => 320 return "ENOTBLK"; 321 case EBUSY => 322 return "EBUSY"; 323 case EEXIST => 324 return "EEXIST"; 325 case EXDEV => 326 return "EXDEV"; 327 case ENODEV => 328 return "ENODEV"; 329 case ENOTDIR => 330 return "ENOTDIR"; 331 case EISDIR => 332 return "EISDIR"; 333 case EINVAL => 334 return "EINVAL"; 335 case ENFILE => 336 return "ENFILE"; 337 case EMFILE => 338 return "EMFILE"; 339 case ENOTTY => 340 return "ENOTTY"; 341 case ETXTBSY => 342 return "ETXTBSY"; 343 case EFBIG => 344 return "EFBIG"; 345 case ENOSPC => 346 return "ENOSPC"; 347 case ESPIPE => 348 return "ESPIPE"; 349 case EROFS => 350 return "EROFS"; 351 case EMLINK => 352 return "EMLINK"; 353 case EPIPE => 354 return "EPIPE"; 355 case EDOM => 356 return "EDOM"; 357 case ERANGE => 358 return "ERANGE"; 359 case EDEADLK => 360 return "EDEADLK"; 361 case ENAMETOOLONG => 362 return "ENAMETOOLONG"; 363 case ENOLCK => 364 return "ENOLCK"; 365 case ENOSYS => 366 return "ENOSYS"; 367 case ENOTEMPTY => 368 return "ENOTEMPTY"; 369 case ELOOP => 370 return "ELOOP"; 371 case ENOMSG => 372 return "ENOMSG"; 373 case EIDRM => 374 return "EIDRM"; 375 case ECHRNG => 376 return "ECHRNG"; 377 case EL2NSYNC => 378 return "EL2NSYNC"; 379 case EL3HLT => 380 return "EL3HLT"; 381 case EL3RST => 382 return "EL3RST"; 383 case ELNRNG => 384 return "ELNRNG"; 385 case EUNATCH => 386 return "EUNATCH"; 387 case ENOCSI => 388 return "ENOCSI"; 389 case EL2HLT => 390 return "EL2HLT"; 391 case EBADE => 392 return "EBADE"; 393 case EBADR => 394 return "EBADR"; 395 case EXFULL => 396 return "EXFULL"; 397 case ENOANO => 398 return "ENOANO"; 399 case EBADRQC => 400 return "EBADRQC"; 401 case EBADSLT => 402 return "EBADSLT"; 403 case EBFONT => 404 return "EBFONT"; 405 case ENOSTR => 406 return "ENOSTR"; 407 case ENODATA => 408 return "ENODATA"; 409 case ETIME => 410 return "ETIME"; 411 case ENOSR => 412 return "ENOSR"; 413 case ENONET => 414 return "ENONET"; 415 case ENOPKG => 416 return "ENOPKG"; 417 case EREMOTE => 418 return "EREMOTE"; 419 case ENOLINK => 420 return "ENOLINK"; 421 case EADV => 422 return "EADV"; 423 case ESRMNT => 424 return "ESRMNT"; 425 case ECOMM => 426 return "ECOMM"; 427 case EPROTO => 428 return "EPROTO"; 429 case EMULTIHOP => 430 return "EMULTIHOP"; 431 case EDOTDOT => 432 return "EDOTDOT"; 433 case EBADMSG => 434 return "EBADMSG"; 435 case EOVERFLOW => 436 return "EOVERFLOW"; 437 case ENOTUNIQ => 438 return "ENOTUNIQ"; 439 case EBADFD => 440 return "EBADFD"; 441 case EREMCHG => 442 return "EREMCHG"; 443 case ELIBACC => 444 return "ELIBACC"; 445 case ELIBBAD => 446 return "ELIBBAD"; 447 case ELIBSCN => 448 return "ELIBSCN"; 449 case ELIBMAX => 450 return "ELIBMAX"; 451 case ELIBEXEC => 452 return "ELIBEXEC"; 453 case EILSEQ => 454 return "EILSEQ"; 455 case ERESTART => 456 return "ERESTART"; 457 case ESTRPIPE => 458 return "ESTRPIPE"; 459 case EUSERS => 460 return "EUSERS"; 461 case ENOTSOCK => 462 return "ENOTSOCK"; 463 case EDESTADDRREQ => 464 return "EDESTADDRREQ"; 465 case EMSGSIZE => 466 return "EMSGSIZE"; 467 case EPROTOTYPE => 468 return "EPROTOTYPE"; 469 case ENOPROTOOPT => 470 return "ENOPROTOOPT"; 471 case EPROTONOSUPPORT => 472 return "EPROTONOSUPPORT"; 473 case ESOCKTNOSUPPORT => 474 return "ESOCKTNOSUPPORT"; 475 case EOPNOTSUPP => 476 return "EOPNOTSUPP"; 477 case EPFNOSUPPORT => 478 return "EPFNOSUPPORT"; 479 case EAFNOSUPPORT => 480 return "EAFNOSUPPORT"; 481 case EADDRINUSE => 482 return "EADDRINUSE"; 483 case EADDRNOTAVAIL => 484 return "EADDRNOTAVAIL"; 485 case ENETDOWN => 486 return "ENETDOWN"; 487 case ENETUNREACH => 488 return "ENETUNREACH"; 489 case ENETRESET => 490 return "ENETRESET"; 491 case ECONNABORTED => 492 return "ECONNABORTED"; 493 case ECONNRESET => 494 return "ECONNRESET"; 495 case ENOBUFS => 496 return "ENOBUFS"; 497 case EISCONN => 498 return "EISCONN"; 499 case ENOTCONN => 500 return "ENOTCONN"; 501 case ESHUTDOWN => 502 return "ESHUTDOWN"; 503 case ETOOMANYREFS => 504 return "ETOOMANYREFS"; 505 case ETIMEDOUT => 506 return "ETIMEDOUT"; 507 case ECONNREFUSED => 508 return "ECONNREFUSED"; 509 case EHOSTDOWN => 510 return "EHOSTDOWN"; 511 case EHOSTUNREACH => 512 return "EHOSTUNREACH"; 513 case EALREADY => 514 return "EALREADY"; 515 case EINPROGRESS => 516 return "EINPROGRESS"; 517 case ESTALE => 518 return "ESTALE"; 519 case EUCLEAN => 520 return "EUCLEAN"; 521 case ENOTNAM => 522 return "ENOTNAM"; 523 case ENAVAIL => 524 return "ENAVAIL"; 525 case EISNAM => 526 return "EISNAM"; 527 case EREMOTEIO => 528 return "EREMOTEIO"; 529 case EDQUOT => 530 return "EDQUOT"; 531 case ENOMEDIUM => 532 return "ENOMEDIUM"; 533 case EMEDIUMTYPE => 534 return "EMEDIUMTYPE"; 535 case ECANCELED => 536 return "ECANCELED"; 537 case ENOKEY => 538 return "ENOKEY"; 539 case EKEYEXPIRED => 540 return "EKEYEXPIRED"; 541 case EKEYREVOKED => 542 return "EKEYREVOKED"; 543 case EKEYREJECTED => 544 return "EKEYREJECTED"; 545 case EOWNERDEAD => 546 return "EOWNERDEAD"; 547 case ENOTRECOVERABLE => 548 return "ENOTRECOVERABLE"; 549 case ERFKILL => 550 return "ERFKILL"; 551 case EHWPOISON => 552 return "EHWPOISON"; 553 case => 554 return unknown_errno(err); 555 }; 556 }; 557 558 export def EPERM: errno = 1; 559 export def ENOENT: errno = 2; 560 export def ESRCH: errno = 3; 561 export def EINTR: errno = 4; 562 export def EIO: errno = 5; 563 export def ENXIO: errno = 6; 564 export def E2BIG: errno = 7; 565 export def ENOEXEC: errno = 8; 566 export def EBADF: errno = 9; 567 export def ECHILD: errno = 10; 568 export def EAGAIN: errno = 11; 569 export def EWOULDBLOCK: errno = EAGAIN; 570 export def ENOMEM: errno = 12; 571 export def EACCES: errno = 13; 572 export def EFAULT: errno = 14; 573 export def ENOTBLK: errno = 15; 574 export def EBUSY: errno = 16; 575 export def EEXIST: errno = 17; 576 export def EXDEV: errno = 18; 577 export def ENODEV: errno = 19; 578 export def ENOTDIR: errno = 20; 579 export def EISDIR: errno = 21; 580 export def EINVAL: errno = 22; 581 export def ENFILE: errno = 23; 582 export def EMFILE: errno = 24; 583 export def ENOTTY: errno = 25; 584 export def ETXTBSY: errno = 26; 585 export def EFBIG: errno = 27; 586 export def ENOSPC: errno = 28; 587 export def ESPIPE: errno = 29; 588 export def EROFS: errno = 30; 589 export def EMLINK: errno = 31; 590 export def EPIPE: errno = 32; 591 export def EDOM: errno = 33; 592 export def ERANGE: errno = 34; 593 export def EDEADLK: errno = 35; 594 export def ENAMETOOLONG: errno = 36; 595 export def ENOLCK: errno = 37; 596 export def ENOSYS: errno = 38; 597 export def ENOTEMPTY: errno = 39; 598 export def ELOOP: errno = 40; 599 export def ENOMSG: errno = 42; 600 export def EIDRM: errno = 43; 601 export def ECHRNG: errno = 44; 602 export def EL2NSYNC: errno = 45; 603 export def EL3HLT: errno = 46; 604 export def EL3RST: errno = 47; 605 export def ELNRNG: errno = 48; 606 export def EUNATCH: errno = 49; 607 export def ENOCSI: errno = 50; 608 export def EL2HLT: errno = 51; 609 export def EBADE: errno = 52; 610 export def EBADR: errno = 53; 611 export def EXFULL: errno = 54; 612 export def ENOANO: errno = 55; 613 export def EBADRQC: errno = 56; 614 export def EBADSLT: errno = 57; 615 export def EBFONT: errno = 59; 616 export def ENOSTR: errno = 60; 617 export def ENODATA: errno = 61; 618 export def ETIME: errno = 62; 619 export def ENOSR: errno = 63; 620 export def ENONET: errno = 64; 621 export def ENOPKG: errno = 65; 622 export def EREMOTE: errno = 66; 623 export def ENOLINK: errno = 67; 624 export def EADV: errno = 68; 625 export def ESRMNT: errno = 69; 626 export def ECOMM: errno = 70; 627 export def EPROTO: errno = 71; 628 export def EMULTIHOP: errno = 72; 629 export def EDOTDOT: errno = 73; 630 export def EBADMSG: errno = 74; 631 export def EOVERFLOW: errno = 75; 632 export def ENOTUNIQ: errno = 76; 633 export def EBADFD: errno = 77; 634 export def EREMCHG: errno = 78; 635 export def ELIBACC: errno = 79; 636 export def ELIBBAD: errno = 80; 637 export def ELIBSCN: errno = 81; 638 export def ELIBMAX: errno = 82; 639 export def ELIBEXEC: errno = 83; 640 export def EILSEQ: errno = 84; 641 export def ERESTART: errno = 85; 642 export def ESTRPIPE: errno = 86; 643 export def EUSERS: errno = 87; 644 export def ENOTSOCK: errno = 88; 645 export def EDESTADDRREQ: errno = 89; 646 export def EMSGSIZE: errno = 90; 647 export def EPROTOTYPE: errno = 91; 648 export def ENOPROTOOPT: errno = 92; 649 export def EPROTONOSUPPORT: errno = 93; 650 export def ESOCKTNOSUPPORT: errno = 94; 651 export def EOPNOTSUPP: errno = 95; 652 export def ENOTSUP: errno = EOPNOTSUPP; 653 export def EPFNOSUPPORT: errno = 96; 654 export def EAFNOSUPPORT: errno = 97; 655 export def EADDRINUSE: errno = 98; 656 export def EADDRNOTAVAIL: errno = 99; 657 export def ENETDOWN: errno = 100; 658 export def ENETUNREACH: errno = 101; 659 export def ENETRESET: errno = 102; 660 export def ECONNABORTED: errno = 103; 661 export def ECONNRESET: errno = 104; 662 export def ENOBUFS: errno = 105; 663 export def EISCONN: errno = 106; 664 export def ENOTCONN: errno = 107; 665 export def ESHUTDOWN: errno = 108; 666 export def ETOOMANYREFS: errno = 109; 667 export def ETIMEDOUT: errno = 110; 668 export def ECONNREFUSED: errno = 111; 669 export def EHOSTDOWN: errno = 112; 670 export def EHOSTUNREACH: errno = 113; 671 export def EALREADY: errno = 114; 672 export def EINPROGRESS: errno = 115; 673 export def ESTALE: errno = 116; 674 export def EUCLEAN: errno = 117; 675 export def ENOTNAM: errno = 118; 676 export def ENAVAIL: errno = 119; 677 export def EISNAM: errno = 120; 678 export def EREMOTEIO: errno = 121; 679 export def EDQUOT: errno = 122; 680 export def ENOMEDIUM: errno = 123; 681 export def EMEDIUMTYPE: errno = 124; 682 export def ECANCELED: errno = 125; 683 export def ENOKEY: errno = 126; 684 export def EKEYEXPIRED: errno = 127; 685 export def EKEYREVOKED: errno = 128; 686 export def EKEYREJECTED: errno = 129; 687 export def EOWNERDEAD: errno = 130; 688 export def ENOTRECOVERABLE: errno = 131; 689 export def ERFKILL: errno = 132; 690 export def EHWPOISON: errno = 133;