2 * Copyright 2005-2009, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT license.
5 * Copyright 2001, Dan Sinclair. All rights reserved.
6 * Distributed under the terms of the NewOS License.
13 #include <SupportDefs.h>
16 static const struct error_base
{
20 {B_GENERAL_ERROR_BASE
, "General "},
21 {B_OS_ERROR_BASE
, "OS "},
22 {B_APP_ERROR_BASE
, "Application Kit "},
23 {B_INTERFACE_ERROR_BASE
, "Interface Kit "},
24 {B_MEDIA_ERROR_BASE
, "Media Kit "},
25 {B_TRANSLATION_ERROR_BASE
, "Translation Kit "},
26 {B_MIDI_ERROR_BASE
, "Midi Kit "},
27 {B_STORAGE_ERROR_BASE
, "Storage Kit "},
28 {B_POSIX_ERROR_BASE
, "POSIX "},
29 {B_MAIL_ERROR_BASE
, "Mail Kit "},
30 {B_PRINT_ERROR_BASE
, "Print "},
31 {B_DEVICE_ERROR_BASE
, "Device "},
32 {B_ERRORS_END
, "Application "},
34 static const uint32 kNumErrorBases
= sizeof(kErrorBases
)
35 / sizeof(struct error_base
);
39 error_description(int error
)
47 return "General system error";
52 return "Out of memory";
56 case B_PERMISSION_DENIED
:
58 return "Permission denied";
60 return "Index not in range for the data set";
62 return "Bad argument type passed to function";
65 return "Invalid Argument";
66 case B_MISMATCHED_VALUES
:
67 return "Mismatched values passed to function";
68 case B_NAME_NOT_FOUND
:
69 return "Name not found";
74 return "Operation timed out";
77 return "Interrupted system call";
81 return "Operation would block";
83 return "Operation canceled";
85 return "Initialization failed";
88 return "Device/File/Resource busy";
91 return "Operation not allowed";
95 return "No, really, don't do that";
100 return "Bad semaphore ID";
102 return "No more semaphores";
104 case B_BAD_THREAD_ID
:
105 return "Bad thread ID";
106 case B_NO_MORE_THREADS
:
107 return "No more threads";
108 case B_BAD_THREAD_STATE
:
109 return "Thread is inappropriate state";
111 return "Operation on invalid team";
112 case B_NO_MORE_TEAMS
:
113 return "No more teams";
116 return "Bad port ID";
117 case B_NO_MORE_PORTS
:
118 return "No more ports available"; // "No more ports"
121 return "Bad image ID";
124 return "Bad address";
125 case B_NOT_AN_EXECUTABLE
:
127 return "Not an executable";
128 case B_MISSING_LIBRARY
:
129 return "Missing library";
130 case B_MISSING_SYMBOL
:
131 return "Symbol not found";
132 case B_UNKNOWN_EXECUTABLE
:
133 return "Unknown executable format";
134 case B_LEGACY_EXECUTABLE
:
135 return "Unsupported legacy executable";
137 case B_DEBUGGER_ALREADY_INSTALLED
:
138 return "Debugger already installed for this team";
140 // Application Kit Errors
143 return "Invalid or unwanted reply";
144 case B_DUPLICATE_REPLY
:
145 return "Duplicate reply";
146 case B_MESSAGE_TO_SELF
:
147 return "Can't send message to self";
149 return "Bad handler";
150 case B_ALREADY_RUNNING
:
151 return "Already running";
152 case B_LAUNCH_FAILED
:
153 return "Launch failed";
154 case B_AMBIGUOUS_APP_LAUNCH
:
155 return "Ambiguous app launch";
156 case B_UNKNOWN_MIME_TYPE
:
157 return "Unknown MIME type";
158 case B_BAD_SCRIPT_SYNTAX
:
159 return "Bad script syntax";
160 case B_LAUNCH_FAILED_NO_RESOLVE_LINK
:
161 return "Could not resolve a link";
162 case B_LAUNCH_FAILED_EXECUTABLE
:
163 return "File is mistakenly marked as executable";
164 case B_LAUNCH_FAILED_APP_NOT_FOUND
:
165 return "Application could not be found";
166 case B_LAUNCH_FAILED_APP_IN_TRASH
:
167 return "Application is in the trash";
168 case B_LAUNCH_FAILED_NO_PREFERRED_APP
:
169 return "There is no preferred application for this type of file";
170 case B_LAUNCH_FAILED_FILES_APP_NOT_FOUND
:
171 return "This file has a preferred app, but it could not be found";
172 case B_BAD_MIME_SNIFFER_RULE
:
173 return "Bad sniffer rule";
174 case B_NOT_A_MESSAGE
:
175 return "Data is not a message";
176 case B_SHUTDOWN_CANCELLED
:
177 return "System shutdown cancelled";
178 case B_SHUTTING_DOWN
:
179 return "System shutting down";
181 // Storage Kit Errors
185 return "Bad file descriptor";
186 case B_FILE_NOT_FOUND
:
187 case B_ENTRY_NOT_FOUND
:
189 return "No such file or directory";
192 return "File or Directory already exists";
193 case B_NAME_TOO_LONG
:
195 return "File name too long";
196 case B_NOT_A_DIRECTORY
:
198 return "Not a directory";
199 case B_DIRECTORY_NOT_EMPTY
:
201 return "Directory not empty";
204 return "No space left on device";
205 case B_READ_ONLY_DEVICE
:
207 return "Read-only file system";
208 case B_IS_A_DIRECTORY
:
210 return "Is a directory";
213 return "Too many open files";
214 case B_CROSS_DEVICE_LINK
:
216 return "Cross-device link";
219 return "Too many symbolic links";
222 return "Broken pipe";
224 return "Operation not supported";
225 case B_PARTITION_TOO_SMALL
:
226 return "Partition too small to contain filesystem";
228 return "Data read partially";
229 case B_PARTIAL_WRITE
:
230 return "Data written partially";
234 case B_STREAM_NOT_FOUND
:
235 return "Stream not found";
236 case B_SERVER_NOT_FOUND
:
237 return "Server not found";
238 case B_RESOURCE_NOT_FOUND
:
239 return "Resource not found";
240 case B_RESOURCE_UNAVAILABLE
:
241 return "Resource unavailable";
242 case B_BAD_SUBSCRIBER
:
243 return "Bad subscriber";
244 case B_SUBSCRIBER_NOT_ENTERED
:
245 return "Subscriber not entered";
246 case B_BUFFER_NOT_AVAILABLE
:
247 return "Buffer not available";
248 case B_LAST_BUFFER_ERROR
:
249 return "Last buffer";
250 case B_MEDIA_SYSTEM_FAILURE
:
251 return "System failure";
252 case B_MEDIA_BAD_NODE
:
253 return "Bad media node";
254 case B_MEDIA_NODE_BUSY
:
255 return "Media node busy";
256 case B_MEDIA_BAD_FORMAT
:
257 return "Bad media format";
258 case B_MEDIA_BAD_BUFFER
:
260 case B_MEDIA_TOO_MANY_NODES
:
261 return "Too many nodes";
262 case B_MEDIA_TOO_MANY_BUFFERS
:
263 return "Too many buffers";
264 case B_MEDIA_NODE_ALREADY_EXISTS
:
265 return "Media node already exists";
266 case B_MEDIA_BUFFER_ALREADY_EXISTS
:
267 return "Buffer already exists";
268 case B_MEDIA_CANNOT_SEEK
:
269 return "Cannot seek";
270 case B_MEDIA_CANNOT_CHANGE_RUN_MODE
:
271 return "Cannot change run mode";
272 case B_MEDIA_APP_ALREADY_REGISTERED
:
273 return "Application already registered";
274 case B_MEDIA_APP_NOT_REGISTERED
:
275 return "Application not registered";
276 case B_MEDIA_CANNOT_RECLAIM_BUFFERS
:
277 return "Cannot reclaim buffers";
278 case B_MEDIA_BUFFERS_NOT_RECLAIMED
:
279 return "Buffers not reclaimed";
280 case B_MEDIA_TIME_SOURCE_STOPPED
:
281 return "Time source stopped";
282 case B_MEDIA_TIME_SOURCE_BUSY
:
283 return "Time source busy";
284 case B_MEDIA_BAD_SOURCE
:
286 case B_MEDIA_BAD_DESTINATION
:
287 return "Bad destination";
288 case B_MEDIA_ALREADY_CONNECTED
:
289 return "Already connected";
290 case B_MEDIA_NOT_CONNECTED
:
291 return "Not connected";
292 case B_MEDIA_BAD_CLIP_FORMAT
:
293 return "Bad clipping format";
294 case B_MEDIA_ADDON_FAILED
:
295 return "Media addon failed";
296 case B_MEDIA_ADDON_DISABLED
:
297 return "Media addon disabled";
298 case B_MEDIA_CHANGE_IN_PROGRESS
:
299 return "Change in progress";
300 case B_MEDIA_STALE_CHANGE_COUNT
:
301 return "Stale change count";
302 case B_MEDIA_ADDON_RESTRICTED
:
303 return "Media addon restricted";
304 case B_MEDIA_NO_HANDLER
:
306 case B_MEDIA_DUPLICATE_FORMAT
:
307 return "Duplicate format";
308 case B_MEDIA_REALTIME_DISABLED
:
309 return "Realtime disabled";
310 case B_MEDIA_REALTIME_UNAVAILABLE
:
311 return "Realtime unavailable";
315 case B_MAIL_NO_DAEMON
:
316 return "No mail daemon";
317 case B_MAIL_UNKNOWN_USER
:
318 return "Unknown mail user";
319 case B_MAIL_WRONG_PASSWORD
:
320 return "Wrong password (mail)";
321 case B_MAIL_UNKNOWN_HOST
:
322 return "Mail unknown host";
323 case B_MAIL_ACCESS_ERROR
:
324 return "Mail access error";
325 case B_MAIL_UNKNOWN_FIELD
:
326 return "Unknown mail field";
327 case B_MAIL_NO_RECIPIENT
:
328 return "No mail recipient";
329 case B_MAIL_INVALID_MAIL
:
330 return "Invalid mail";
334 case B_NO_PRINT_SERVER
:
335 return "No print server";
339 case B_DEV_INVALID_IOCTL
:
340 return "Invalid device ioctl";
341 case B_DEV_NO_MEMORY
:
342 return "No device memory";
343 case B_DEV_BAD_DRIVE_NUM
:
344 return "Bad drive number";
346 return "No media present";
347 case B_DEV_UNREADABLE
:
348 return "Device unreadable";
349 case B_DEV_FORMAT_ERROR
:
350 return "Device format error";
352 return "Device timeout";
353 case B_DEV_RECALIBRATE_ERROR
:
354 return "Device recalibrate error";
355 case B_DEV_SEEK_ERROR
:
356 return "Device seek error";
358 return "Device ID error";
359 case B_DEV_READ_ERROR
:
360 return "Device read error";
361 case B_DEV_WRITE_ERROR
:
362 return "Device write error";
363 case B_DEV_NOT_READY
:
364 return "Device not ready";
365 case B_DEV_MEDIA_CHANGED
:
366 return "Device media changed";
367 case B_DEV_MEDIA_CHANGE_REQUESTED
:
368 return "Device media change requested";
369 case B_DEV_RESOURCE_CONFLICT
:
370 return "Resource conflict";
371 case B_DEV_CONFIGURATION_ERROR
:
372 return "Configuration error";
373 case B_DEV_DISABLED_BY_USER
:
374 return "Disabled by user";
375 case B_DEV_DOOR_OPEN
:
376 return "Drive door open";
378 // the commented out ones are really strange error codes...
379 //case B_DEV_INVALID_PIPE:
381 case B_DEV_CRC_ERROR
:
382 return "Device check-sum error";
384 return "Device stalled";
386 //case B_DEV_BAD_PID:
387 //case B_DEV_UNEXPECTED_PID:
389 case B_DEV_DATA_OVERRUN
:
390 return "Device data overrun";
391 case B_DEV_DATA_UNDERRUN
:
392 return "Device data underrun";
393 case B_DEV_FIFO_OVERRUN
:
394 return "Device FIFO overrun";
395 case B_DEV_FIFO_UNDERRUN
:
396 return "Device FIFO underrun";
398 return "Device pending";
399 case B_DEV_MULTIPLE_ERRORS
:
400 return "Multiple device errors";
402 return "Device too late";
404 // Translation Kit Errors
406 case B_NO_TRANSLATOR
:
407 return "No translator found";
409 return "Illegal data";
411 // Other POSIX Errors
414 return "File table overflow";
416 return "Device not accessible";
418 return "Seek not allowed on file descriptor";
420 return "Function not implemented";
422 return "Numerical argument out of range"; // "Domain Error"
424 return "No buffer space available";
426 return "Argument too big";
428 return "No child process";
430 return "Resource deadlock";
432 return "File too large";
434 return "Too many links";
436 return "No such device";
438 return "No record locks available";
442 return "No such process";
444 return "File Position Error";
446 return "Signal Error";
448 return "Range Error";
451 return "Protocol wrong type for socket";
452 case EPROTONOSUPPORT
:
453 return "Protocol not supported";
455 return "Protocol family not supported";
457 return "Address family not supported by protocol family";
459 return "Address already in use";
461 return "Can't assign requested address";
463 return "Network is down";
465 return "Network is unreachable";
467 return "Network dropped connection on reset";
469 return "Software caused connection abort";
471 return "Connection reset by peer";
473 return "Socket is already connected";
475 return "Socket is not connected";
477 return "Can't send after socket shutdown";
479 return "Connection refused";
481 return "No route to host";
483 return "Protocol option not available";
485 return "Operation now in progress";
487 return "Operation already in progress";
489 return "Illegal byte sequence";
491 return "No message of desired type";
493 return "Stale file handle";
496 return "Value too large for defined type";
498 return "Message too long";
500 return "Operation not supported";
502 return "Socket operation on non-socket";
504 return "Host is down";
506 return "Bad message";
508 return "Operation canceled";
510 return "Destination address required";
514 return "Identifier removed";
518 return "No message available";
522 return "No STREAM resources";
524 return "Not a STREAM";
526 return "Not supported";
528 return "Protocol error";
530 return "STREAM ioctl() timeout";
532 return "Text file busy";
534 return "No such attribute";
545 static char unknown
[48];
548 char *description
= error_description(error
);
549 if (description
!= NULL
)
553 const char *system
= "";
554 for (i
= 0; i
< kNumErrorBases
; i
++) {
555 if (kErrorBases
[i
].base
<= error
556 && ((i
+ 1 < kNumErrorBases
&& kErrorBases
[i
+ 1].base
> error
)
557 || i
+ 1 == kNumErrorBases
)) {
558 system
= kErrorBases
[i
].name
;
562 sprintf(unknown
, "Unknown %sError (%d)", system
, error
);
564 sprintf(unknown
, "No Error (%d)", error
);
571 strerror_r(int error
, char *buffer
, size_t bufferSize
)
573 char *description
= error_description(error
);
574 if (description
== NULL
)
577 strlcpy(buffer
, description
, bufferSize
);
579 // TODO: could return ERANGE if buffer is too small