1 /* 2 * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5 6 7 #include <SupportDefs.h> 8 9 #include <stdio.h> 10 #include <string.h> 11 #include <stdlib.h> 12 13 14 extern const char *__progname; 15 16 struct error_pair { 17 status_t value; 18 const char *name; 19 } kErrorNames[] = { 20 #define E(e) { e, #e } 21 // generated by: 22 // tr ' ,=\t()+' '\n\n\n\n\n\n\n' <headers/os/support/Errors.h | grep '\(^B_\|^E[A-Z]\)' | sort | uniq | awk '{ print "\tE(" $1 ")," }' 23 E(B_ALREADY_RUNNING), 24 E(B_AMBIGUOUS_APP_LAUNCH), 25 E(B_APP_ERROR_BASE), 26 E(B_BAD_ADDRESS), 27 E(B_BAD_DATA), 28 E(B_BAD_HANDLER), 29 E(B_BAD_IMAGE_ID), 30 E(B_BAD_INDEX), 31 E(B_BAD_MIME_SNIFFER_RULE), 32 E(B_BAD_PORT_ID), 33 E(B_BAD_REPLY), 34 E(B_BAD_SCRIPT_SYNTAX), 35 E(B_BAD_SEM_ID), 36 E(B_BAD_SUBSCRIBER), 37 E(B_BAD_TEAM_ID), 38 E(B_BAD_THREAD_ID), 39 E(B_BAD_THREAD_STATE), 40 E(B_BAD_TYPE), 41 E(B_BAD_VALUE), 42 E(B_BUFFER_NOT_AVAILABLE), 43 E(B_BUFFER_OVERFLOW), 44 E(B_BUSTED_PIPE), 45 E(B_BUSY), 46 E(B_CANCELED), 47 E(B_CROSS_DEVICE_LINK), 48 E(B_DEBUGGER_ALREADY_INSTALLED), 49 E(B_DEVICE_ERROR_BASE), 50 E(B_DEVICE_FULL), 51 E(B_DEVICE_NOT_FOUND), 52 E(B_DEV_BAD_DRIVE_NUM), 53 E(B_DEV_BAD_PID), 54 E(B_DEV_CONFIGURATION_ERROR), 55 E(B_DEV_CRC_ERROR), 56 E(B_DEV_DATA_OVERRUN), 57 E(B_DEV_DATA_UNDERRUN), 58 E(B_DEV_DISABLED_BY_USER), 59 E(B_DEV_DOOR_OPEN), 60 E(B_DEV_FIFO_OVERRUN), 61 E(B_DEV_FIFO_UNDERRUN), 62 E(B_DEV_FORMAT_ERROR), 63 E(B_DEV_ID_ERROR), 64 E(B_DEV_INVALID_IOCTL), 65 E(B_DEV_INVALID_PIPE), 66 E(B_DEV_MEDIA_CHANGED), 67 E(B_DEV_MEDIA_CHANGE_REQUESTED), 68 E(B_DEV_MULTIPLE_ERRORS), 69 E(B_DEV_NOT_READY), 70 E(B_DEV_NO_MEDIA), 71 E(B_DEV_NO_MEMORY), 72 E(B_DEV_PENDING), 73 E(B_DEV_READ_ERROR), 74 E(B_DEV_RECALIBRATE_ERROR), 75 E(B_DEV_RESOURCE_CONFLICT), 76 E(B_DEV_SEEK_ERROR), 77 E(B_DEV_STALLED), 78 E(B_DEV_TIMEOUT), 79 E(B_DEV_TOO_LATE), 80 E(B_DEV_UNEXPECTED_PID), 81 E(B_DEV_UNREADABLE), 82 E(B_DEV_WRITE_ERROR), 83 E(B_DIRECTORY_NOT_EMPTY), 84 E(B_DONT_DO_THAT), 85 E(B_DUPLICATE_REPLY), 86 E(B_ENTRY_NOT_FOUND), 87 E(B_ERROR), 88 E(B_ERRORS_END), 89 E(B_FILE_ERROR), 90 E(B_FILE_EXISTS), 91 E(B_FILE_NOT_FOUND), 92 E(B_FILE_TOO_LARGE), 93 E(B_GENERAL_ERROR_BASE), 94 E(B_INTERFACE_ERROR_BASE), 95 E(B_INTERRUPTED), 96 E(B_IO_ERROR), 97 E(B_IS_A_DIRECTORY), 98 E(B_LAST_BUFFER_ERROR), 99 E(B_LAUNCH_FAILED), 100 E(B_LAUNCH_FAILED_APP_IN_TRASH), 101 E(B_LAUNCH_FAILED_APP_NOT_FOUND), 102 E(B_LAUNCH_FAILED_EXECUTABLE), 103 E(B_LAUNCH_FAILED_FILES_APP_NOT_FOUND), 104 E(B_LAUNCH_FAILED_NO_PREFERRED_APP), 105 E(B_LAUNCH_FAILED_NO_RESOLVE_LINK), 106 E(B_LINK_LIMIT), 107 E(B_MAIL_ACCESS_ERROR), 108 E(B_MAIL_ERROR_BASE), 109 E(B_MAIL_INVALID_MAIL), 110 E(B_MAIL_NO_DAEMON), 111 E(B_MAIL_NO_RECIPIENT), 112 E(B_MAIL_UNKNOWN_FIELD), 113 E(B_MAIL_UNKNOWN_HOST), 114 E(B_MAIL_UNKNOWN_USER), 115 E(B_MAIL_WRONG_PASSWORD), 116 E(B_MEDIA_ERROR_BASE), 117 E(B_MESSAGE_TO_SELF), 118 E(B_MIDI_ERROR_BASE), 119 E(B_MISMATCHED_VALUES), 120 E(B_MISSING_LIBRARY), 121 E(B_MISSING_SYMBOL), 122 E(B_NAME_IN_USE), 123 E(B_NAME_NOT_FOUND), 124 E(B_NAME_TOO_LONG), 125 E(B_NOT_ALLOWED), 126 E(B_NOT_AN_EXECUTABLE), 127 E(B_NOT_A_DIRECTORY), 128 E(B_NOT_A_MESSAGE), 129 E(B_NOT_SUPPORTED), 130 E(B_NO_ERROR), 131 E(B_NO_INIT), 132 E(B_NO_MEMORY), 133 E(B_NO_MORE_FDS), 134 E(B_NO_MORE_PORTS), 135 E(B_NO_MORE_SEMS), 136 E(B_NO_MORE_TEAMS), 137 E(B_NO_MORE_THREADS), 138 E(B_NO_PRINT_SERVER), 139 E(B_OK), 140 E(B_OS_ERROR_BASE), 141 E(B_PARTITION_TOO_SMALL), 142 E(B_PERMISSION_DENIED), 143 E(B_POSIX_ERROR_BASE), 144 E(B_PRINT_ERROR_BASE), 145 E(B_READ_ONLY_DEVICE), 146 E(B_RESOURCE_NOT_FOUND), 147 E(B_RESOURCE_UNAVAILABLE), 148 E(B_RESULT_NOT_REPRESENTABLE), 149 E(B_SERVER_NOT_FOUND), 150 E(B_SHUTDOWN_CANCELLED), 151 E(B_SHUTTING_DOWN), 152 E(B_STORAGE_ERROR_BASE), 153 E(B_STREAM_NOT_FOUND), 154 E(B_SUBSCRIBER_NOT_ENTERED), 155 E(B_TIMED_OUT), 156 E(B_TOO_MANY_ARGS), 157 E(B_TRANSLATION_ERROR_BASE), 158 E(B_UNKNOWN_MIME_TYPE), 159 E(B_UNSUPPORTED), 160 E(B_WOULD_BLOCK), 161 E(EACCES), 162 E(EADDRINUSE), 163 E(EADDRNOTAVAIL), 164 E(EAFNOSUPPORT), 165 E(EAGAIN), 166 E(EALREADY), 167 E(EBADF), 168 E(EBADMSG), 169 E(EBUSY), 170 E(ECANCELED), 171 E(ECHILD), 172 E(ECONNABORTED), 173 E(ECONNREFUSED), 174 E(ECONNRESET), 175 E(EDEADLK), 176 E(EDESTADDRREQ), 177 E(EDOM), 178 E(EDQUOT), 179 E(EEXIST), 180 E(EFAULT), 181 E(EFBIG), 182 E(EFPOS), 183 E(EHOSTDOWN), 184 E(EHOSTUNREACH), 185 E(EIDRM), 186 E(EILSEQ), 187 E(EINPROGRESS), 188 E(EINTR), 189 E(EINVAL), 190 E(EIO), 191 E(EISCONN), 192 E(EISDIR), 193 E(ELOOP), 194 E(EMFILE), 195 E(EMLINK), 196 E(EMSGSIZE), 197 E(EMULTIHOP), 198 E(ENAMETOOLONG), 199 E(ENETDOWN), 200 E(ENETRESET), 201 E(ENETUNREACH), 202 E(ENFILE), 203 E(ENOBUFS), 204 E(ENODATA), 205 E(ENODEV), 206 E(ENOENT), 207 E(ENOEXEC), 208 E(ENOLCK), 209 E(ENOLINK), 210 E(ENOMEM), 211 E(ENOMSG), 212 E(ENOPROTOOPT), 213 E(ENOSPC), 214 E(ENOSR), 215 E(ENOSTR), 216 E(ENOSYS), 217 E(ENOTCONN), 218 E(ENOTDIR), 219 E(ENOTEMPTY), 220 E(ENOTSOCK), 221 E(ENOTSUP), 222 E(ENOTTY), 223 E(ENXIO), 224 E(EOPNOTSUPP), 225 E(EOVERFLOW), 226 E(EPERM), 227 E(EPFNOSUPPORT), 228 E(EPIPE), 229 E(EPROTO), 230 E(EPROTONOSUPPORT), 231 E(EPROTOTYPE), 232 E(ERANGE), 233 E(EROFS), 234 E(ESHUTDOWN), 235 E(ESIGPARM), 236 E(ESPIPE), 237 E(ESRCH), 238 E(ESTALE), 239 E(ETIME), 240 E(ETIMEDOUT), 241 E(ETXTBSY), 242 E(EWOULDBLOCK), 243 E(EXDEV), 244 { 0, NULL } 245 }; 246 247 248 static void 249 usage(void) 250 { 251 fprintf(stderr, "usage: %s <error number>\n" 252 "Prints clear text error messages for given error numbers.\n", __progname); 253 exit(-1); 254 } 255 256 257 static void 258 print_error(char *number) 259 { 260 char *end; 261 int32 error = (int32)strtoll(number, &end, 0); 262 // strtol() cuts off hex numbers that have the highest bit set 263 264 if (end[0]) { 265 // not a number, check names 266 int i; 267 struct error_pair *p = kErrorNames; 268 while (p->name && strcmp(p->name, number)) 269 p++; 270 if (!p->name) { 271 fprintf(stderr, "%s: invalid number (%s)\n", __progname, number); 272 exit(1); 273 } 274 error = p->value; 275 } 276 277 printf("0x%lx: %s\n", error, strerror(error)); 278 } 279 280 281 int 282 main(int argc, char *argv[]) 283 { 284 int32 i; 285 286 if (argc < 2) 287 usage(); 288 289 for (i = 1; i < argc; i++) { 290 print_error(argv[i]); 291 } 292 293 return 0; 294 } 295