117049c45SAxel Dörfler /*
217049c45SAxel Dörfler * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
317049c45SAxel Dörfler * Distributed under the terms of the MIT License.
417049c45SAxel Dörfler */
517049c45SAxel Dörfler
617049c45SAxel Dörfler
717049c45SAxel Dörfler #include <SupportDefs.h>
817049c45SAxel Dörfler
917049c45SAxel Dörfler #include <stdio.h>
1017049c45SAxel Dörfler #include <string.h>
1117049c45SAxel Dörfler #include <stdlib.h>
1217049c45SAxel Dörfler
1317049c45SAxel Dörfler
1417049c45SAxel Dörfler extern const char *__progname;
1517049c45SAxel Dörfler
16d70beedcSFrançois Revol struct error_pair {
17d70beedcSFrançois Revol status_t value;
18d70beedcSFrançois Revol const char *name;
19d70beedcSFrançois Revol } kErrorNames[] = {
2068e6a23cSFrançois Revol #define E(e) { e, #e }
21d70beedcSFrançois Revol // generated by:
22c87d0ba1SFrançois Revol // tr ' ,=\t()+' '\n\n\n\n\n\n\n' <headers/os/support/Errors.h | grep '\(^B_\|^E[A-Z0-9]\)' | sort | uniq | awk '{ print "\tE(" $1 ")," }'
2368e6a23cSFrançois Revol E(B_ALREADY_RUNNING),
2468e6a23cSFrançois Revol E(B_AMBIGUOUS_APP_LAUNCH),
2568e6a23cSFrançois Revol E(B_APP_ERROR_BASE),
2668e6a23cSFrançois Revol E(B_BAD_ADDRESS),
2768e6a23cSFrançois Revol E(B_BAD_DATA),
2868e6a23cSFrançois Revol E(B_BAD_HANDLER),
2968e6a23cSFrançois Revol E(B_BAD_IMAGE_ID),
3068e6a23cSFrançois Revol E(B_BAD_INDEX),
3168e6a23cSFrançois Revol E(B_BAD_MIME_SNIFFER_RULE),
3268e6a23cSFrançois Revol E(B_BAD_PORT_ID),
3368e6a23cSFrançois Revol E(B_BAD_REPLY),
3468e6a23cSFrançois Revol E(B_BAD_SCRIPT_SYNTAX),
3568e6a23cSFrançois Revol E(B_BAD_SEM_ID),
3668e6a23cSFrançois Revol E(B_BAD_SUBSCRIBER),
3768e6a23cSFrançois Revol E(B_BAD_TEAM_ID),
3868e6a23cSFrançois Revol E(B_BAD_THREAD_ID),
3968e6a23cSFrançois Revol E(B_BAD_THREAD_STATE),
4068e6a23cSFrançois Revol E(B_BAD_TYPE),
4168e6a23cSFrançois Revol E(B_BAD_VALUE),
4268e6a23cSFrançois Revol E(B_BUFFER_NOT_AVAILABLE),
43c87d0ba1SFrançois Revol #ifdef B_BUFFER_OVERFLOW
4468e6a23cSFrançois Revol E(B_BUFFER_OVERFLOW),
45c87d0ba1SFrançois Revol #endif
4668e6a23cSFrançois Revol E(B_BUSTED_PIPE),
4768e6a23cSFrançois Revol E(B_BUSY),
4868e6a23cSFrançois Revol E(B_CANCELED),
4968e6a23cSFrançois Revol E(B_CROSS_DEVICE_LINK),
5068e6a23cSFrançois Revol E(B_DEBUGGER_ALREADY_INSTALLED),
5168e6a23cSFrançois Revol E(B_DEVICE_ERROR_BASE),
5268e6a23cSFrançois Revol E(B_DEVICE_FULL),
53c87d0ba1SFrançois Revol #ifdef B_DEVICE_NOT_FOUND
5468e6a23cSFrançois Revol E(B_DEVICE_NOT_FOUND),
55c87d0ba1SFrançois Revol #endif
5668e6a23cSFrançois Revol E(B_DEV_BAD_DRIVE_NUM),
5768e6a23cSFrançois Revol E(B_DEV_BAD_PID),
5868e6a23cSFrançois Revol E(B_DEV_CONFIGURATION_ERROR),
5968e6a23cSFrançois Revol E(B_DEV_CRC_ERROR),
6068e6a23cSFrançois Revol E(B_DEV_DATA_OVERRUN),
6168e6a23cSFrançois Revol E(B_DEV_DATA_UNDERRUN),
6268e6a23cSFrançois Revol E(B_DEV_DISABLED_BY_USER),
6368e6a23cSFrançois Revol E(B_DEV_DOOR_OPEN),
6468e6a23cSFrançois Revol E(B_DEV_FIFO_OVERRUN),
6568e6a23cSFrançois Revol E(B_DEV_FIFO_UNDERRUN),
6668e6a23cSFrançois Revol E(B_DEV_FORMAT_ERROR),
6768e6a23cSFrançois Revol E(B_DEV_ID_ERROR),
6868e6a23cSFrançois Revol E(B_DEV_INVALID_IOCTL),
6968e6a23cSFrançois Revol E(B_DEV_INVALID_PIPE),
7068e6a23cSFrançois Revol E(B_DEV_MEDIA_CHANGED),
7168e6a23cSFrançois Revol E(B_DEV_MEDIA_CHANGE_REQUESTED),
7268e6a23cSFrançois Revol E(B_DEV_MULTIPLE_ERRORS),
7368e6a23cSFrançois Revol E(B_DEV_NOT_READY),
7468e6a23cSFrançois Revol E(B_DEV_NO_MEDIA),
7568e6a23cSFrançois Revol E(B_DEV_NO_MEMORY),
7668e6a23cSFrançois Revol E(B_DEV_PENDING),
7768e6a23cSFrançois Revol E(B_DEV_READ_ERROR),
7868e6a23cSFrançois Revol E(B_DEV_RECALIBRATE_ERROR),
7968e6a23cSFrançois Revol E(B_DEV_RESOURCE_CONFLICT),
8068e6a23cSFrançois Revol E(B_DEV_SEEK_ERROR),
8168e6a23cSFrançois Revol E(B_DEV_STALLED),
8268e6a23cSFrançois Revol E(B_DEV_TIMEOUT),
8368e6a23cSFrançois Revol E(B_DEV_TOO_LATE),
8468e6a23cSFrançois Revol E(B_DEV_UNEXPECTED_PID),
8568e6a23cSFrançois Revol E(B_DEV_UNREADABLE),
8668e6a23cSFrançois Revol E(B_DEV_WRITE_ERROR),
8768e6a23cSFrançois Revol E(B_DIRECTORY_NOT_EMPTY),
8868e6a23cSFrançois Revol E(B_DONT_DO_THAT),
8968e6a23cSFrançois Revol E(B_DUPLICATE_REPLY),
9068e6a23cSFrançois Revol E(B_ENTRY_NOT_FOUND),
9168e6a23cSFrançois Revol E(B_ERROR),
9268e6a23cSFrançois Revol E(B_ERRORS_END),
9368e6a23cSFrançois Revol E(B_FILE_ERROR),
9468e6a23cSFrançois Revol E(B_FILE_EXISTS),
95*b47e8b0cSAugustin Cavalier #ifdef __HAIKU_BEOS_COMPATIBLE
96eb1d596fSAugustin Cavalier #define B_FILE_NOT_FOUND (B_STORAGE_ERROR_BASE + 1)
9768e6a23cSFrançois Revol E(B_FILE_NOT_FOUND),
98c87d0ba1SFrançois Revol #endif
99eb1d596fSAugustin Cavalier E(B_FILE_TOO_LARGE),
10068e6a23cSFrançois Revol E(B_GENERAL_ERROR_BASE),
10168e6a23cSFrançois Revol E(B_INTERFACE_ERROR_BASE),
10268e6a23cSFrançois Revol E(B_INTERRUPTED),
10368e6a23cSFrançois Revol E(B_IO_ERROR),
10468e6a23cSFrançois Revol E(B_IS_A_DIRECTORY),
10568e6a23cSFrançois Revol E(B_LAST_BUFFER_ERROR),
10668e6a23cSFrançois Revol E(B_LAUNCH_FAILED),
10768e6a23cSFrançois Revol E(B_LAUNCH_FAILED_APP_IN_TRASH),
10868e6a23cSFrançois Revol E(B_LAUNCH_FAILED_APP_NOT_FOUND),
10968e6a23cSFrançois Revol E(B_LAUNCH_FAILED_EXECUTABLE),
11068e6a23cSFrançois Revol E(B_LAUNCH_FAILED_FILES_APP_NOT_FOUND),
11168e6a23cSFrançois Revol E(B_LAUNCH_FAILED_NO_PREFERRED_APP),
11268e6a23cSFrançois Revol E(B_LAUNCH_FAILED_NO_RESOLVE_LINK),
11368e6a23cSFrançois Revol E(B_LINK_LIMIT),
11468e6a23cSFrançois Revol E(B_MAIL_ACCESS_ERROR),
11568e6a23cSFrançois Revol E(B_MAIL_ERROR_BASE),
11668e6a23cSFrançois Revol E(B_MAIL_INVALID_MAIL),
11768e6a23cSFrançois Revol E(B_MAIL_NO_DAEMON),
11868e6a23cSFrançois Revol E(B_MAIL_NO_RECIPIENT),
11968e6a23cSFrançois Revol E(B_MAIL_UNKNOWN_FIELD),
12068e6a23cSFrançois Revol E(B_MAIL_UNKNOWN_HOST),
12168e6a23cSFrançois Revol E(B_MAIL_UNKNOWN_USER),
12268e6a23cSFrançois Revol E(B_MAIL_WRONG_PASSWORD),
12368e6a23cSFrançois Revol E(B_MEDIA_ERROR_BASE),
12468e6a23cSFrançois Revol E(B_MESSAGE_TO_SELF),
12568e6a23cSFrançois Revol E(B_MIDI_ERROR_BASE),
12668e6a23cSFrançois Revol E(B_MISMATCHED_VALUES),
12768e6a23cSFrançois Revol E(B_MISSING_LIBRARY),
12868e6a23cSFrançois Revol E(B_MISSING_SYMBOL),
12968e6a23cSFrançois Revol E(B_NAME_IN_USE),
13068e6a23cSFrançois Revol E(B_NAME_NOT_FOUND),
13168e6a23cSFrançois Revol E(B_NAME_TOO_LONG),
13268e6a23cSFrançois Revol E(B_NOT_ALLOWED),
13368e6a23cSFrançois Revol E(B_NOT_AN_EXECUTABLE),
13468e6a23cSFrançois Revol E(B_NOT_A_DIRECTORY),
13568e6a23cSFrançois Revol E(B_NOT_A_MESSAGE),
136c87d0ba1SFrançois Revol #ifdef B_NOT_SUPPORTED
13768e6a23cSFrançois Revol E(B_NOT_SUPPORTED),
138c87d0ba1SFrançois Revol #endif
13968e6a23cSFrançois Revol E(B_NO_ERROR),
14068e6a23cSFrançois Revol E(B_NO_INIT),
14168e6a23cSFrançois Revol E(B_NO_MEMORY),
14268e6a23cSFrançois Revol E(B_NO_MORE_FDS),
14368e6a23cSFrançois Revol E(B_NO_MORE_PORTS),
14468e6a23cSFrançois Revol E(B_NO_MORE_SEMS),
14568e6a23cSFrançois Revol E(B_NO_MORE_TEAMS),
14668e6a23cSFrançois Revol E(B_NO_MORE_THREADS),
14768e6a23cSFrançois Revol E(B_NO_PRINT_SERVER),
14868e6a23cSFrançois Revol E(B_OK),
14968e6a23cSFrançois Revol E(B_OS_ERROR_BASE),
150dec78bb2SIngo Weinhold E(B_PARTIAL_READ),
151dec78bb2SIngo Weinhold E(B_PARTIAL_WRITE),
15268e6a23cSFrançois Revol E(B_PARTITION_TOO_SMALL),
15368e6a23cSFrançois Revol E(B_PERMISSION_DENIED),
15468e6a23cSFrançois Revol E(B_POSIX_ERROR_BASE),
15568e6a23cSFrançois Revol E(B_PRINT_ERROR_BASE),
15668e6a23cSFrançois Revol E(B_READ_ONLY_DEVICE),
15768e6a23cSFrançois Revol E(B_RESOURCE_NOT_FOUND),
15868e6a23cSFrançois Revol E(B_RESOURCE_UNAVAILABLE),
159c87d0ba1SFrançois Revol #ifdef B_RESULT_NOT_REPRESENTABLE
16068e6a23cSFrançois Revol E(B_RESULT_NOT_REPRESENTABLE),
161c87d0ba1SFrançois Revol #endif
16268e6a23cSFrançois Revol E(B_SERVER_NOT_FOUND),
163c87d0ba1SFrançois Revol #ifdef B_SHUTDOWN_CANCELLED
16468e6a23cSFrançois Revol E(B_SHUTDOWN_CANCELLED),
165c87d0ba1SFrançois Revol #endif
166c87d0ba1SFrançois Revol #ifdef B_SHUTTING_DOWN
16768e6a23cSFrançois Revol E(B_SHUTTING_DOWN),
168c87d0ba1SFrançois Revol #endif
16968e6a23cSFrançois Revol E(B_STORAGE_ERROR_BASE),
17068e6a23cSFrançois Revol E(B_STREAM_NOT_FOUND),
17168e6a23cSFrançois Revol E(B_SUBSCRIBER_NOT_ENTERED),
17268e6a23cSFrançois Revol E(B_TIMED_OUT),
173c87d0ba1SFrançois Revol #ifdef B_TOO_MANY_ARGS
17468e6a23cSFrançois Revol E(B_TOO_MANY_ARGS),
175c87d0ba1SFrançois Revol #endif
17668e6a23cSFrançois Revol E(B_TRANSLATION_ERROR_BASE),
17768e6a23cSFrançois Revol E(B_UNKNOWN_MIME_TYPE),
17868e6a23cSFrançois Revol E(B_UNSUPPORTED),
17968e6a23cSFrançois Revol E(B_WOULD_BLOCK),
180c87d0ba1SFrançois Revol E(E2BIG),
18168e6a23cSFrançois Revol E(EACCES),
18268e6a23cSFrançois Revol E(EADDRINUSE),
18368e6a23cSFrançois Revol E(EADDRNOTAVAIL),
18468e6a23cSFrançois Revol E(EAFNOSUPPORT),
18568e6a23cSFrançois Revol E(EAGAIN),
18668e6a23cSFrançois Revol E(EALREADY),
18768e6a23cSFrançois Revol E(EBADF),
188c87d0ba1SFrançois Revol #ifdef EBADMSG
18968e6a23cSFrançois Revol E(EBADMSG),
190c87d0ba1SFrançois Revol #endif
19168e6a23cSFrançois Revol E(EBUSY),
192c87d0ba1SFrançois Revol #ifdef ECANCELED
19368e6a23cSFrançois Revol E(ECANCELED),
194c87d0ba1SFrançois Revol #endif
19568e6a23cSFrançois Revol E(ECHILD),
19668e6a23cSFrançois Revol E(ECONNABORTED),
19768e6a23cSFrançois Revol E(ECONNREFUSED),
19868e6a23cSFrançois Revol E(ECONNRESET),
19968e6a23cSFrançois Revol E(EDEADLK),
200c87d0ba1SFrançois Revol #ifdef EDESTADDRREQ
20168e6a23cSFrançois Revol E(EDESTADDRREQ),
202c87d0ba1SFrançois Revol #endif
20368e6a23cSFrançois Revol E(EDOM),
204c87d0ba1SFrançois Revol #ifdef EDQUOT
20568e6a23cSFrançois Revol E(EDQUOT),
206c87d0ba1SFrançois Revol #endif
20768e6a23cSFrançois Revol E(EEXIST),
20868e6a23cSFrançois Revol E(EFAULT),
20968e6a23cSFrançois Revol E(EFBIG),
21068e6a23cSFrançois Revol E(EFPOS),
211c87d0ba1SFrançois Revol #ifdef EHOSTDOWN
21268e6a23cSFrançois Revol E(EHOSTDOWN),
213c87d0ba1SFrançois Revol #endif
21468e6a23cSFrançois Revol E(EHOSTUNREACH),
215c87d0ba1SFrançois Revol #ifdef EIDRM
21668e6a23cSFrançois Revol E(EIDRM),
217c87d0ba1SFrançois Revol #endif
21868e6a23cSFrançois Revol E(EILSEQ),
21968e6a23cSFrançois Revol E(EINPROGRESS),
22068e6a23cSFrançois Revol E(EINTR),
22168e6a23cSFrançois Revol E(EINVAL),
22268e6a23cSFrançois Revol E(EIO),
22368e6a23cSFrançois Revol E(EISCONN),
22468e6a23cSFrançois Revol E(EISDIR),
22568e6a23cSFrançois Revol E(ELOOP),
22668e6a23cSFrançois Revol E(EMFILE),
22768e6a23cSFrançois Revol E(EMLINK),
22868e6a23cSFrançois Revol E(EMSGSIZE),
229c87d0ba1SFrançois Revol #ifdef EMULTIHOP
23068e6a23cSFrançois Revol E(EMULTIHOP),
231c87d0ba1SFrançois Revol #endif
23268e6a23cSFrançois Revol E(ENAMETOOLONG),
23368e6a23cSFrançois Revol E(ENETDOWN),
23468e6a23cSFrançois Revol E(ENETRESET),
23568e6a23cSFrançois Revol E(ENETUNREACH),
23668e6a23cSFrançois Revol E(ENFILE),
23768e6a23cSFrançois Revol E(ENOBUFS),
238c87d0ba1SFrançois Revol #ifdef ENODATA
23968e6a23cSFrançois Revol E(ENODATA),
240c87d0ba1SFrançois Revol #endif
24168e6a23cSFrançois Revol E(ENODEV),
24268e6a23cSFrançois Revol E(ENOENT),
24368e6a23cSFrançois Revol E(ENOEXEC),
24468e6a23cSFrançois Revol E(ENOLCK),
245c87d0ba1SFrançois Revol #ifdef ENOLINK
24668e6a23cSFrançois Revol E(ENOLINK),
247c87d0ba1SFrançois Revol #endif
24868e6a23cSFrançois Revol E(ENOMEM),
24968e6a23cSFrançois Revol E(ENOMSG),
25068e6a23cSFrançois Revol E(ENOPROTOOPT),
25168e6a23cSFrançois Revol E(ENOSPC),
252c87d0ba1SFrançois Revol #ifdef ENOSR
25368e6a23cSFrançois Revol E(ENOSR),
254c87d0ba1SFrançois Revol #endif
255c87d0ba1SFrançois Revol #ifdef ENOSTR
25668e6a23cSFrançois Revol E(ENOSTR),
257c87d0ba1SFrançois Revol #endif
25868e6a23cSFrançois Revol E(ENOSYS),
25968e6a23cSFrançois Revol E(ENOTCONN),
26068e6a23cSFrançois Revol E(ENOTDIR),
26168e6a23cSFrançois Revol E(ENOTEMPTY),
26268e6a23cSFrançois Revol E(ENOTSOCK),
263c87d0ba1SFrançois Revol #ifdef ENOTSUP
26468e6a23cSFrançois Revol E(ENOTSUP),
265c87d0ba1SFrançois Revol #endif
26668e6a23cSFrançois Revol E(ENOTTY),
26768e6a23cSFrançois Revol E(ENXIO),
26868e6a23cSFrançois Revol E(EOPNOTSUPP),
26968e6a23cSFrançois Revol E(EOVERFLOW),
27068e6a23cSFrançois Revol E(EPERM),
27168e6a23cSFrançois Revol E(EPFNOSUPPORT),
27268e6a23cSFrançois Revol E(EPIPE),
273c87d0ba1SFrançois Revol #ifdef EPROTO
27468e6a23cSFrançois Revol E(EPROTO),
275c87d0ba1SFrançois Revol #endif
27668e6a23cSFrançois Revol E(EPROTONOSUPPORT),
27768e6a23cSFrançois Revol E(EPROTOTYPE),
27868e6a23cSFrançois Revol E(ERANGE),
27968e6a23cSFrançois Revol E(EROFS),
28068e6a23cSFrançois Revol E(ESHUTDOWN),
28168e6a23cSFrançois Revol E(ESIGPARM),
28268e6a23cSFrançois Revol E(ESPIPE),
28368e6a23cSFrançois Revol E(ESRCH),
28468e6a23cSFrançois Revol E(ESTALE),
285c87d0ba1SFrançois Revol #ifdef ETIME
28668e6a23cSFrançois Revol E(ETIME),
287c87d0ba1SFrançois Revol #endif
28868e6a23cSFrançois Revol E(ETIMEDOUT),
289c87d0ba1SFrançois Revol #ifdef ETXTBSY
29068e6a23cSFrançois Revol E(ETXTBSY),
291c87d0ba1SFrançois Revol #endif
29252b4ed60SJérôme Duval E(ENOATTR),
29352b4ed60SJérôme Duval #ifdef ENOTRECOVERABLE
29452b4ed60SJérôme Duval E(ENOTRECOVERABLE),
29552b4ed60SJérôme Duval #endif
29652b4ed60SJérôme Duval #ifdef EOWNERDEAD
29752b4ed60SJérôme Duval E(EOWNERDEAD),
29852b4ed60SJérôme Duval #endif
29968e6a23cSFrançois Revol E(EWOULDBLOCK),
30068e6a23cSFrançois Revol E(EXDEV),
301d70beedcSFrançois Revol { 0, NULL }
302d70beedcSFrançois Revol };
303d70beedcSFrançois Revol
30417049c45SAxel Dörfler
30517049c45SAxel Dörfler static void
usage(void)30617049c45SAxel Dörfler usage(void)
30717049c45SAxel Dörfler {
30817049c45SAxel Dörfler fprintf(stderr, "usage: %s <error number>\n"
30917049c45SAxel Dörfler "Prints clear text error messages for given error numbers.\n", __progname);
31017049c45SAxel Dörfler exit(-1);
31117049c45SAxel Dörfler }
31217049c45SAxel Dörfler
31317049c45SAxel Dörfler
31417049c45SAxel Dörfler static void
print_error(char * number)31517049c45SAxel Dörfler print_error(char *number)
31617049c45SAxel Dörfler {
31717049c45SAxel Dörfler char *end;
31817049c45SAxel Dörfler int32 error = (int32)strtoll(number, &end, 0);
31917049c45SAxel Dörfler // strtol() cuts off hex numbers that have the highest bit set
32017049c45SAxel Dörfler
32117049c45SAxel Dörfler if (end[0]) {
322d70beedcSFrançois Revol // not a number, check names
323d70beedcSFrançois Revol struct error_pair *p = kErrorNames;
324d70beedcSFrançois Revol while (p->name && strcmp(p->name, number))
325d70beedcSFrançois Revol p++;
326d70beedcSFrançois Revol if (!p->name) {
32717049c45SAxel Dörfler fprintf(stderr, "%s: invalid number (%s)\n", __progname, number);
32817049c45SAxel Dörfler exit(1);
32917049c45SAxel Dörfler }
330d70beedcSFrançois Revol error = p->value;
331d70beedcSFrançois Revol }
33217049c45SAxel Dörfler
3338110732bSAlex Smith printf("0x%" B_PRIx32 ": %s\n", error, strerror(error));
33417049c45SAxel Dörfler }
33517049c45SAxel Dörfler
33617049c45SAxel Dörfler
33717049c45SAxel Dörfler int
main(int argc,char * argv[])33817049c45SAxel Dörfler main(int argc, char *argv[])
33917049c45SAxel Dörfler {
34017049c45SAxel Dörfler int32 i;
34117049c45SAxel Dörfler
34217049c45SAxel Dörfler if (argc < 2)
34317049c45SAxel Dörfler usage();
34417049c45SAxel Dörfler
34517049c45SAxel Dörfler for (i = 1; i < argc; i++) {
34617049c45SAxel Dörfler print_error(argv[i]);
34717049c45SAxel Dörfler }
34817049c45SAxel Dörfler
34917049c45SAxel Dörfler return 0;
35017049c45SAxel Dörfler }
351