/* * Copyright 2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved. * Distributed under the terms of the MIT License. */ #include #include #include #include extern const char *__progname; struct error_pair { status_t value; const char *name; } kErrorNames[] = { #define E(e) { e, #e } // generated by: // tr ' ,=\t()+' '\n\n\n\n\n\n\n' \n" "Prints clear text error messages for given error numbers.\n", __progname); exit(-1); } static void print_error(char *number) { char *end; int32 error = (int32)strtoll(number, &end, 0); // strtol() cuts off hex numbers that have the highest bit set if (end[0]) { // not a number, check names 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%" B_PRIx32 ": %s\n", error, strerror(error)); } int main(int argc, char *argv[]) { int32 i; if (argc < 2) usage(); for (i = 1; i < argc; i++) { print_error(argv[i]); } return 0; }