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