| | @@ -1003,6 +1003,154 @@ |
| 1003 | 1003 | return n, k; |
| 1004 | 1004 | end; |
| 1005 | 1005 | |
| 1006 | +const |
| 1007 | + (* what each errno means, as glibc's strerror says it; 41 and 58 |
| 1008 | + are none *) |
| 1009 | + errorTexts: [134][]U8 = [ |
| 1010 | + "Success", (* 0 *) |
| 1011 | + "Operation not permitted", (* 1, EPERM *) |
| 1012 | + "No such file or directory", (* 2, ENOENT *) |
| 1013 | + "No such process", (* 3, ESRCH *) |
| 1014 | + "Interrupted system call", (* 4, EINTR *) |
| 1015 | + "Input/output error", (* 5, EIO *) |
| 1016 | + "No such device or address", (* 6, ENXIO *) |
| 1017 | + "Argument list too long", (* 7, E2BIG *) |
| 1018 | + "Exec format error", (* 8, ENOEXEC *) |
| 1019 | + "Bad file descriptor", (* 9, EBADF *) |
| 1020 | + "No child processes", (* 10, ECHILD *) |
| 1021 | + "Resource temporarily unavailable", (* 11, EAGAIN *) |
| 1022 | + "Cannot allocate memory", (* 12, ENOMEM *) |
| 1023 | + "Permission denied", (* 13, EACCES *) |
| 1024 | + "Bad address", (* 14, EFAULT *) |
| 1025 | + "Block device required", (* 15, ENOTBLK *) |
| 1026 | + "Device or resource busy", (* 16, EBUSY *) |
| 1027 | + "File exists", (* 17, EEXIST *) |
| 1028 | + "Invalid cross-device link", (* 18, EXDEV *) |
| 1029 | + "No such device", (* 19, ENODEV *) |
| 1030 | + "Not a directory", (* 20, ENOTDIR *) |
| 1031 | + "Is a directory", (* 21, EISDIR *) |
| 1032 | + "Invalid argument", (* 22, EINVAL *) |
| 1033 | + "Too many open files in system", (* 23, ENFILE *) |
| 1034 | + "Too many open files", (* 24, EMFILE *) |
| 1035 | + "Inappropriate ioctl for device", (* 25, ENOTTY *) |
| 1036 | + "Text file busy", (* 26, ETXTBSY *) |
| 1037 | + "File too large", (* 27, EFBIG *) |
| 1038 | + "No space left on device", (* 28, ENOSPC *) |
| 1039 | + "Illegal seek", (* 29, ESPIPE *) |
| 1040 | + "Read-only file system", (* 30, EROFS *) |
| 1041 | + "Too many links", (* 31, EMLINK *) |
| 1042 | + "Broken pipe", (* 32, EPIPE *) |
| 1043 | + "Numerical argument out of domain", (* 33, EDOM *) |
| 1044 | + "Numerical result out of range", (* 34, ERANGE *) |
| 1045 | + "Resource deadlock avoided", (* 35, EDEADLOCK *) |
| 1046 | + "File name too long", (* 36, ENAMETOOLONG *) |
| 1047 | + "No locks available", (* 37, ENOLCK *) |
| 1048 | + "Function not implemented", (* 38, ENOSYS *) |
| 1049 | + "Directory not empty", (* 39, ENOTEMPTY *) |
| 1050 | + "Too many levels of symbolic links", (* 40, ELOOP *) |
| 1051 | + "unknown error", (* 41 *) |
| 1052 | + "No message of desired type", (* 42, ENOMSG *) |
| 1053 | + "Identifier removed", (* 43, EIDRM *) |
| 1054 | + "Channel number out of range", (* 44, ECHRNG *) |
| 1055 | + "Level 2 not synchronized", (* 45, EL2NSYNC *) |
| 1056 | + "Level 3 halted", (* 46, EL3HLT *) |
| 1057 | + "Level 3 reset", (* 47, EL3RST *) |
| 1058 | + "Link number out of range", (* 48, ELNRNG *) |
| 1059 | + "Protocol driver not attached", (* 49, EUNATCH *) |
| 1060 | + "No CSI structure available", (* 50, ENOCSI *) |
| 1061 | + "Level 2 halted", (* 51, EL2HLT *) |
| 1062 | + "Invalid exchange", (* 52, EBADE *) |
| 1063 | + "Invalid request descriptor", (* 53, EBADR *) |
| 1064 | + "Exchange full", (* 54, EXFULL *) |
| 1065 | + "No anode", (* 55, ENOANO *) |
| 1066 | + "Invalid request code", (* 56, EBADRQC *) |
| 1067 | + "Invalid slot", (* 57, EBADSLT *) |
| 1068 | + "unknown error", (* 58 *) |
| 1069 | + "Bad font file format", (* 59, EBFONT *) |
| 1070 | + "Device not a stream", (* 60, ENOSTR *) |
| 1071 | + "No data available", (* 61, ENODATA *) |
| 1072 | + "Timer expired", (* 62, ETIME *) |
| 1073 | + "Out of streams resources", (* 63, ENOSR *) |
| 1074 | + "Machine is not on the network", (* 64, ENONET *) |
| 1075 | + "Package not installed", (* 65, ENOPKG *) |
| 1076 | + "Object is remote", (* 66, EREMOTE *) |
| 1077 | + "Link has been severed", (* 67, ENOLINK *) |
| 1078 | + "Advertise error", (* 68, EADV *) |
| 1079 | + "Srmount error", (* 69, ESRMNT *) |
| 1080 | + "Communication error on send", (* 70, ECOMM *) |
| 1081 | + "Protocol error", (* 71, EPROTO *) |
| 1082 | + "Multihop attempted", (* 72, EMULTIHOP *) |
| 1083 | + "RFS specific error", (* 73, EDOTDOT *) |
| 1084 | + "Bad message", (* 74, EBADMSG *) |
| 1085 | + "Value too large for defined data type", (* 75, EOVERFLOW *) |
| 1086 | + "Name not unique on network", (* 76, ENOTUNIQ *) |
| 1087 | + "File descriptor in bad state", (* 77, EBADFD *) |
| 1088 | + "Remote address changed", (* 78, EREMCHG *) |
| 1089 | + "Can not access a needed shared library", (* 79, ELIBACC *) |
| 1090 | + "Accessing a corrupted shared library", (* 80, ELIBBAD *) |
| 1091 | + ".lib section in a.out corrupted", (* 81, ELIBSCN *) |
| 1092 | + "Attempting to link in too many shared libraries", (* 82, ELIBMAX *) |
| 1093 | + "Cannot exec a shared library directly", (* 83, ELIBEXEC *) |
| 1094 | + "Invalid or incomplete multibyte or wide character", (* 84, EILSEQ *) |
| 1095 | + "Interrupted system call should be restarted", (* 85, ERESTART *) |
| 1096 | + "Streams pipe error", (* 86, ESTRPIPE *) |
| 1097 | + "Too many users", (* 87, EUSERS *) |
| 1098 | + "Socket operation on non-socket", (* 88, ENOTSOCK *) |
| 1099 | + "Destination address required", (* 89, EDESTADDRREQ *) |
| 1100 | + "Message too long", (* 90, EMSGSIZE *) |
| 1101 | + "Protocol wrong type for socket", (* 91, EPROTOTYPE *) |
| 1102 | + "Protocol not available", (* 92, ENOPROTOOPT *) |
| 1103 | + "Protocol not supported", (* 93, EPROTONOSUPPORT *) |
| 1104 | + "Socket type not supported", (* 94, ESOCKTNOSUPPORT *) |
| 1105 | + "Operation not supported", (* 95, ENOTSUP *) |
| 1106 | + "Protocol family not supported", (* 96, EPFNOSUPPORT *) |
| 1107 | + "Address family not supported by protocol", (* 97, EAFNOSUPPORT *) |
| 1108 | + "Address already in use", (* 98, EADDRINUSE *) |
| 1109 | + "Cannot assign requested address", (* 99, EADDRNOTAVAIL *) |
| 1110 | + "Network is down", (* 100, ENETDOWN *) |
| 1111 | + "Network is unreachable", (* 101, ENETUNREACH *) |
| 1112 | + "Network dropped connection on reset", (* 102, ENETRESET *) |
| 1113 | + "Software caused connection abort", (* 103, ECONNABORTED *) |
| 1114 | + "Connection reset by peer", (* 104, ECONNRESET *) |
| 1115 | + "No buffer space available", (* 105, ENOBUFS *) |
| 1116 | + "Transport endpoint is already connected", (* 106, EISCONN *) |
| 1117 | + "Transport endpoint is not connected", (* 107, ENOTCONN *) |
| 1118 | + "Cannot send after transport endpoint shutdown", (* 108, ESHUTDOWN *) |
| 1119 | + "Too many references: cannot splice", (* 109, ETOOMANYREFS *) |
| 1120 | + "Connection timed out", (* 110, ETIMEDOUT *) |
| 1121 | + "Connection refused", (* 111, ECONNREFUSED *) |
| 1122 | + "Host is down", (* 112, EHOSTDOWN *) |
| 1123 | + "No route to host", (* 113, EHOSTUNREACH *) |
| 1124 | + "Operation already in progress", (* 114, EALREADY *) |
| 1125 | + "Operation now in progress", (* 115, EINPROGRESS *) |
| 1126 | + "Stale file handle", (* 116, ESTALE *) |
| 1127 | + "Structure needs cleaning", (* 117, EUCLEAN *) |
| 1128 | + "Not a XENIX named type file", (* 118, ENOTNAM *) |
| 1129 | + "No XENIX semaphores available", (* 119, ENAVAIL *) |
| 1130 | + "Is a named type file", (* 120, EISNAM *) |
| 1131 | + "Remote I/O error", (* 121, EREMOTEIO *) |
| 1132 | + "Disk quota exceeded", (* 122, EDQUOT *) |
| 1133 | + "No medium found", (* 123, ENOMEDIUM *) |
| 1134 | + "Wrong medium type", (* 124, EMEDIUMTYPE *) |
| 1135 | + "Operation canceled", (* 125, ECANCELED *) |
| 1136 | + "Required key not available", (* 126, ENOKEY *) |
| 1137 | + "Key has expired", (* 127, EKEYEXPIRED *) |
| 1138 | + "Key has been revoked", (* 128, EKEYREVOKED *) |
| 1139 | + "Key was rejected by service", (* 129, EKEYREJECTED *) |
| 1140 | + "Owner died", (* 130, EOWNERDEAD *) |
| 1141 | + "State not recoverable", (* 131, ENOTRECOVERABLE *) |
| 1142 | + "Operation not possible due to RF-kill", (* 132, ERFKILL *) |
| 1143 | + "Memory page has hardware error" (* 133, EHWPOISON *)]; |
| 1144 | + |
| 1145 | +(* What errno err, or minus it, means, as C's strerror says it; |
| 1146 | + "unknown error" for a number that is no errno. *) |
| 1147 | +proc errorText*(err: INT): []U8; |
| 1148 | +begin |
| 1149 | + if (err < 0) and (err > -LEN(errorTexts)) then err := -err; end; |
| 1150 | + if (err < 0) or (err >= LEN(errorTexts)) then return "unknown error"; end; |
| 1151 | + return errorTexts[err]; |
| 1152 | +end; |
| 1153 | + |
| 1006 | 1154 | (* The value of the environment variable name; "" if it isn't set. The |
| 1007 | 1155 | environment follows the arguments and their nil. *) |
| 1008 | 1156 | proc env*(name: []U8): []U8; |
| | @@ -1894,6 +2042,8 @@ |
| 1894 | 2042 | if (n # 5) or (buf[0..5] # "hello") or (read(fd, buf) # 0) then exit(2); end; |
| 1895 | 2043 | close(fd); |
| 1896 | 2044 | if openRead("/no/such/file") >= 0 then exit(2); end; |
| 2045 | + if (errorText(-2) # "No such file or directory") or (errorText(13) # "Permission denied") |
| 2046 | + or (errorText(41) # "unknown error") or (errorText(134) # "unknown error") then exit(2); end; |
| 1897 | 2047 | if isTerminal(-1) then exit(2); end; |
| 1898 | 2048 | p := mmap(100); |
| 1899 | 2049 | if (p = nil) or (p[99] # 0) then exit(2); end; |