Now also accepts symbolic names for errors; handy sometimes to get the value or message of a cryptic EFOO.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20116 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
François Revol 2007-02-09 10:16:38 +00:00
parent 22c6ae6951
commit d70beedc0a

View File

@ -13,6 +13,236 @@
extern const char *__progname;
struct error_pair {
status_t value;
const char *name;
} kErrorNames[] = {
// generated by:
// tr ' ,=\t()+' '\n\n\n\n\n\n\n' headers/os/support/Errors.h | grep '\(^B_\|^E[A-Z]\)' | sort | uniq | awk '{ print "\t{ " $1 ", \"" $1 "\" }," }'
{ B_ALREADY_RUNNING, "B_ALREADY_RUNNING" },
{ B_AMBIGUOUS_APP_LAUNCH, "B_AMBIGUOUS_APP_LAUNCH" },
{ B_APP_ERROR_BASE, "B_APP_ERROR_BASE" },
{ B_BAD_ADDRESS, "B_BAD_ADDRESS" },
{ B_BAD_DATA, "B_BAD_DATA" },
{ B_BAD_HANDLER, "B_BAD_HANDLER" },
{ B_BAD_IMAGE_ID, "B_BAD_IMAGE_ID" },
{ B_BAD_INDEX, "B_BAD_INDEX" },
{ B_BAD_MIME_SNIFFER_RULE, "B_BAD_MIME_SNIFFER_RULE" },
{ B_BAD_PORT_ID, "B_BAD_PORT_ID" },
{ B_BAD_REPLY, "B_BAD_REPLY" },
{ B_BAD_SCRIPT_SYNTAX, "B_BAD_SCRIPT_SYNTAX" },
{ B_BAD_SEM_ID, "B_BAD_SEM_ID" },
{ B_BAD_SUBSCRIBER, "B_BAD_SUBSCRIBER" },
{ B_BAD_TEAM_ID, "B_BAD_TEAM_ID" },
{ B_BAD_THREAD_ID, "B_BAD_THREAD_ID" },
{ B_BAD_THREAD_STATE, "B_BAD_THREAD_STATE" },
{ B_BAD_TYPE, "B_BAD_TYPE" },
{ B_BAD_VALUE, "B_BAD_VALUE" },
{ B_BUFFER_NOT_AVAILABLE, "B_BUFFER_NOT_AVAILABLE" },
{ B_BUFFER_OVERFLOW, "B_BUFFER_OVERFLOW" },
{ B_BUSTED_PIPE, "B_BUSTED_PIPE" },
{ B_BUSY, "B_BUSY" },
{ B_CANCELED, "B_CANCELED" },
{ B_CROSS_DEVICE_LINK, "B_CROSS_DEVICE_LINK" },
{ B_DEBUGGER_ALREADY_INSTALLED, "B_DEBUGGER_ALREADY_INSTALLED" },
{ B_DEVICE_ERROR_BASE, "B_DEVICE_ERROR_BASE" },
{ B_DEVICE_FULL, "B_DEVICE_FULL" },
{ B_DEVICE_NOT_FOUND, "B_DEVICE_NOT_FOUND" },
{ B_DEV_BAD_DRIVE_NUM, "B_DEV_BAD_DRIVE_NUM" },
{ B_DEV_BAD_PID, "B_DEV_BAD_PID" },
{ B_DEV_CONFIGURATION_ERROR, "B_DEV_CONFIGURATION_ERROR" },
{ B_DEV_CRC_ERROR, "B_DEV_CRC_ERROR" },
{ B_DEV_DATA_OVERRUN, "B_DEV_DATA_OVERRUN" },
{ B_DEV_DATA_UNDERRUN, "B_DEV_DATA_UNDERRUN" },
{ B_DEV_DISABLED_BY_USER, "B_DEV_DISABLED_BY_USER" },
{ B_DEV_DOOR_OPEN, "B_DEV_DOOR_OPEN" },
{ B_DEV_FIFO_OVERRUN, "B_DEV_FIFO_OVERRUN" },
{ B_DEV_FIFO_UNDERRUN, "B_DEV_FIFO_UNDERRUN" },
{ B_DEV_FORMAT_ERROR, "B_DEV_FORMAT_ERROR" },
{ B_DEV_ID_ERROR, "B_DEV_ID_ERROR" },
{ B_DEV_INVALID_IOCTL, "B_DEV_INVALID_IOCTL" },
{ B_DEV_INVALID_PIPE, "B_DEV_INVALID_PIPE" },
{ B_DEV_MEDIA_CHANGED, "B_DEV_MEDIA_CHANGED" },
{ B_DEV_MEDIA_CHANGE_REQUESTED, "B_DEV_MEDIA_CHANGE_REQUESTED" },
{ B_DEV_MULTIPLE_ERRORS, "B_DEV_MULTIPLE_ERRORS" },
{ B_DEV_NOT_READY, "B_DEV_NOT_READY" },
{ B_DEV_NO_MEDIA, "B_DEV_NO_MEDIA" },
{ B_DEV_NO_MEMORY, "B_DEV_NO_MEMORY" },
{ B_DEV_PENDING, "B_DEV_PENDING" },
{ B_DEV_READ_ERROR, "B_DEV_READ_ERROR" },
{ B_DEV_RECALIBRATE_ERROR, "B_DEV_RECALIBRATE_ERROR" },
{ B_DEV_RESOURCE_CONFLICT, "B_DEV_RESOURCE_CONFLICT" },
{ B_DEV_SEEK_ERROR, "B_DEV_SEEK_ERROR" },
{ B_DEV_STALLED, "B_DEV_STALLED" },
{ B_DEV_TIMEOUT, "B_DEV_TIMEOUT" },
{ B_DEV_TOO_LATE, "B_DEV_TOO_LATE" },
{ B_DEV_UNEXPECTED_PID, "B_DEV_UNEXPECTED_PID" },
{ B_DEV_UNREADABLE, "B_DEV_UNREADABLE" },
{ B_DEV_WRITE_ERROR, "B_DEV_WRITE_ERROR" },
{ B_DIRECTORY_NOT_EMPTY, "B_DIRECTORY_NOT_EMPTY" },
{ B_DONT_DO_THAT, "B_DONT_DO_THAT" },
{ B_DUPLICATE_REPLY, "B_DUPLICATE_REPLY" },
{ B_ENTRY_NOT_FOUND, "B_ENTRY_NOT_FOUND" },
{ B_ERROR, "B_ERROR" },
{ B_ERRORS_END, "B_ERRORS_END" },
{ B_FILE_ERROR, "B_FILE_ERROR" },
{ B_FILE_EXISTS, "B_FILE_EXISTS" },
{ B_FILE_NOT_FOUND, "B_FILE_NOT_FOUND" },
{ B_FILE_TOO_LARGE, "B_FILE_TOO_LARGE" },
{ B_GENERAL_ERROR_BASE, "B_GENERAL_ERROR_BASE" },
{ B_INTERFACE_ERROR_BASE, "B_INTERFACE_ERROR_BASE" },
{ B_INTERRUPTED, "B_INTERRUPTED" },
{ B_IO_ERROR, "B_IO_ERROR" },
{ B_IS_A_DIRECTORY, "B_IS_A_DIRECTORY" },
{ B_LAST_BUFFER_ERROR, "B_LAST_BUFFER_ERROR" },
{ B_LAUNCH_FAILED, "B_LAUNCH_FAILED" },
{ B_LAUNCH_FAILED_APP_IN_TRASH, "B_LAUNCH_FAILED_APP_IN_TRASH" },
{ B_LAUNCH_FAILED_APP_NOT_FOUND, "B_LAUNCH_FAILED_APP_NOT_FOUND" },
{ B_LAUNCH_FAILED_EXECUTABLE, "B_LAUNCH_FAILED_EXECUTABLE" },
{ B_LAUNCH_FAILED_FILES_APP_NOT_FOUND, "B_LAUNCH_FAILED_FILES_APP_NOT_FOUND" },
{ B_LAUNCH_FAILED_NO_PREFERRED_APP, "B_LAUNCH_FAILED_NO_PREFERRED_APP" },
{ B_LAUNCH_FAILED_NO_RESOLVE_LINK, "B_LAUNCH_FAILED_NO_RESOLVE_LINK" },
{ B_LINK_LIMIT, "B_LINK_LIMIT" },
{ B_MAIL_ACCESS_ERROR, "B_MAIL_ACCESS_ERROR" },
{ B_MAIL_ERROR_BASE, "B_MAIL_ERROR_BASE" },
{ B_MAIL_INVALID_MAIL, "B_MAIL_INVALID_MAIL" },
{ B_MAIL_NO_DAEMON, "B_MAIL_NO_DAEMON" },
{ B_MAIL_NO_RECIPIENT, "B_MAIL_NO_RECIPIENT" },
{ B_MAIL_UNKNOWN_FIELD, "B_MAIL_UNKNOWN_FIELD" },
{ B_MAIL_UNKNOWN_HOST, "B_MAIL_UNKNOWN_HOST" },
{ B_MAIL_UNKNOWN_USER, "B_MAIL_UNKNOWN_USER" },
{ B_MAIL_WRONG_PASSWORD, "B_MAIL_WRONG_PASSWORD" },
{ B_MEDIA_ERROR_BASE, "B_MEDIA_ERROR_BASE" },
{ B_MESSAGE_TO_SELF, "B_MESSAGE_TO_SELF" },
{ B_MIDI_ERROR_BASE, "B_MIDI_ERROR_BASE" },
{ B_MISMATCHED_VALUES, "B_MISMATCHED_VALUES" },
{ B_MISSING_LIBRARY, "B_MISSING_LIBRARY" },
{ B_MISSING_SYMBOL, "B_MISSING_SYMBOL" },
{ B_NAME_IN_USE, "B_NAME_IN_USE" },
{ B_NAME_NOT_FOUND, "B_NAME_NOT_FOUND" },
{ B_NAME_TOO_LONG, "B_NAME_TOO_LONG" },
{ B_NOT_ALLOWED, "B_NOT_ALLOWED" },
{ B_NOT_AN_EXECUTABLE, "B_NOT_AN_EXECUTABLE" },
{ B_NOT_A_DIRECTORY, "B_NOT_A_DIRECTORY" },
{ B_NOT_A_MESSAGE, "B_NOT_A_MESSAGE" },
{ B_NOT_SUPPORTED, "B_NOT_SUPPORTED" },
{ B_NO_ERROR, "B_NO_ERROR" },
{ B_NO_INIT, "B_NO_INIT" },
{ B_NO_MEMORY, "B_NO_MEMORY" },
{ B_NO_MORE_FDS, "B_NO_MORE_FDS" },
{ B_NO_MORE_PORTS, "B_NO_MORE_PORTS" },
{ B_NO_MORE_SEMS, "B_NO_MORE_SEMS" },
{ B_NO_MORE_TEAMS, "B_NO_MORE_TEAMS" },
{ B_NO_MORE_THREADS, "B_NO_MORE_THREADS" },
{ B_NO_PRINT_SERVER, "B_NO_PRINT_SERVER" },
{ B_OK, "B_OK" },
{ B_OS_ERROR_BASE, "B_OS_ERROR_BASE" },
{ B_PARTITION_TOO_SMALL, "B_PARTITION_TOO_SMALL" },
{ B_PERMISSION_DENIED, "B_PERMISSION_DENIED" },
{ B_POSIX_ERROR_BASE, "B_POSIX_ERROR_BASE" },
{ B_PRINT_ERROR_BASE, "B_PRINT_ERROR_BASE" },
{ B_READ_ONLY_DEVICE, "B_READ_ONLY_DEVICE" },
{ B_RESOURCE_NOT_FOUND, "B_RESOURCE_NOT_FOUND" },
{ B_RESOURCE_UNAVAILABLE, "B_RESOURCE_UNAVAILABLE" },
{ B_RESULT_NOT_REPRESENTABLE, "B_RESULT_NOT_REPRESENTABLE" },
{ B_SERVER_NOT_FOUND, "B_SERVER_NOT_FOUND" },
{ B_SHUTDOWN_CANCELLED, "B_SHUTDOWN_CANCELLED" },
{ B_SHUTTING_DOWN, "B_SHUTTING_DOWN" },
{ B_STORAGE_ERROR_BASE, "B_STORAGE_ERROR_BASE" },
{ B_STREAM_NOT_FOUND, "B_STREAM_NOT_FOUND" },
{ B_SUBSCRIBER_NOT_ENTERED, "B_SUBSCRIBER_NOT_ENTERED" },
{ B_TIMED_OUT, "B_TIMED_OUT" },
{ B_TOO_MANY_ARGS, "B_TOO_MANY_ARGS" },
{ B_TRANSLATION_ERROR_BASE, "B_TRANSLATION_ERROR_BASE" },
{ B_UNKNOWN_MIME_TYPE, "B_UNKNOWN_MIME_TYPE" },
{ B_UNSUPPORTED, "B_UNSUPPORTED" },
{ B_WOULD_BLOCK, "B_WOULD_BLOCK" },
{ EACCES, "EACCES" },
{ EADDRINUSE, "EADDRINUSE" },
{ EADDRNOTAVAIL, "EADDRNOTAVAIL" },
{ EAFNOSUPPORT, "EAFNOSUPPORT" },
{ EAGAIN, "EAGAIN" },
{ EALREADY, "EALREADY" },
{ EBADF, "EBADF" },
{ EBADMSG, "EBADMSG" },
{ EBUSY, "EBUSY" },
{ ECANCELED, "ECANCELED" },
{ ECHILD, "ECHILD" },
{ ECONNABORTED, "ECONNABORTED" },
{ ECONNREFUSED, "ECONNREFUSED" },
{ ECONNRESET, "ECONNRESET" },
{ EDEADLK, "EDEADLK" },
{ EDESTADDRREQ, "EDESTADDRREQ" },
{ EDOM, "EDOM" },
{ EDQUOT, "EDQUOT" },
{ EEXIST, "EEXIST" },
{ EFAULT, "EFAULT" },
{ EFBIG, "EFBIG" },
{ EFPOS, "EFPOS" },
{ EHOSTDOWN, "EHOSTDOWN" },
{ EHOSTUNREACH, "EHOSTUNREACH" },
{ EIDRM, "EIDRM" },
{ EILSEQ, "EILSEQ" },
{ EINPROGRESS, "EINPROGRESS" },
{ EINTR, "EINTR" },
{ EINVAL, "EINVAL" },
{ EIO, "EIO" },
{ EISCONN, "EISCONN" },
{ EISDIR, "EISDIR" },
{ ELOOP, "ELOOP" },
{ EMFILE, "EMFILE" },
{ EMLINK, "EMLINK" },
{ EMSGSIZE, "EMSGSIZE" },
{ EMULTIHOP, "EMULTIHOP" },
{ ENAMETOOLONG, "ENAMETOOLONG" },
{ ENETDOWN, "ENETDOWN" },
{ ENETRESET, "ENETRESET" },
{ ENETUNREACH, "ENETUNREACH" },
{ ENFILE, "ENFILE" },
{ ENOBUFS, "ENOBUFS" },
{ ENODATA, "ENODATA" },
{ ENODEV, "ENODEV" },
{ ENOENT, "ENOENT" },
{ ENOEXEC, "ENOEXEC" },
{ ENOLCK, "ENOLCK" },
{ ENOLINK, "ENOLINK" },
{ ENOMEM, "ENOMEM" },
{ ENOMSG, "ENOMSG" },
{ ENOPROTOOPT, "ENOPROTOOPT" },
{ ENOSPC, "ENOSPC" },
{ ENOSR, "ENOSR" },
{ ENOSTR, "ENOSTR" },
{ ENOSYS, "ENOSYS" },
{ ENOTCONN, "ENOTCONN" },
{ ENOTDIR, "ENOTDIR" },
{ ENOTEMPTY, "ENOTEMPTY" },
{ ENOTSOCK, "ENOTSOCK" },
{ ENOTSUP, "ENOTSUP" },
{ ENOTTY, "ENOTTY" },
{ ENXIO, "ENXIO" },
{ EOPNOTSUPP, "EOPNOTSUPP" },
{ EOVERFLOW, "EOVERFLOW" },
{ EPERM, "EPERM" },
{ EPFNOSUPPORT, "EPFNOSUPPORT" },
{ EPIPE, "EPIPE" },
{ EPROTO, "EPROTO" },
{ EPROTONOSUPPORT, "EPROTONOSUPPORT" },
{ EPROTOTYPE, "EPROTOTYPE" },
{ ERANGE, "ERANGE" },
{ EROFS, "EROFS" },
{ ESHUTDOWN, "ESHUTDOWN" },
{ ESIGPARM, "ESIGPARM" },
{ ESPIPE, "ESPIPE" },
{ ESRCH, "ESRCH" },
{ ESTALE, "ESTALE" },
{ ETIME, "ETIME" },
{ ETIMEDOUT, "ETIMEDOUT" },
{ ETXTBSY, "ETXTBSY" },
{ EWOULDBLOCK, "EWOULDBLOCK" },
{ EXDEV, "EXDEV" },
{ 0, NULL }
};
static void
usage(void)
@ -31,8 +261,16 @@ print_error(char *number)
// strtol() cuts off hex numbers that have the highest bit set
if (end[0]) {
fprintf(stderr, "%s: invalid number (%s)\n", __progname, number);
exit(1);
// not a number, check names
int i;
struct error_pair *p = kErrorNames;
while (p->name && strcmp(p->name, number))
p++;
if (!p->name) {
fprintf(stderr, "%s: invalid number (%s)\n", __progname, number);
exit(1);
}
error = p->value;
}
printf("0x%lx: %s\n", error, strerror(error));