xref: /haiku/src/bin/error.c (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
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 
17 static void
18 usage(void)
19 {
20 	fprintf(stderr, "usage: %s <error number>\n"
21 		"Prints clear text error messages for given error numbers.\n", __progname);
22 	exit(-1);
23 }
24 
25 
26 static void
27 print_error(char *number)
28 {
29 	char *end;
30 	int32 error = (int32)strtoll(number, &end, 0);
31 		// strtol() cuts off hex numbers that have the highest bit set
32 
33 	if (end[0]) {
34 		fprintf(stderr, "%s: invalid number (%s)\n", __progname, number);
35 		exit(1);
36 	}
37 
38 	printf("0x%lx: %s\n", error, strerror(error));
39 }
40 
41 
42 int
43 main(int argc, char *argv[])
44 {
45 	int32 i;
46 
47 	if (argc < 2)
48 		usage();
49 
50 	for (i = 1; i < argc; i++) {
51 		print_error(argv[i]);
52 	}
53 
54 	return 0;
55 }
56