fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / string / strerror.c
blob8bea4b768a74cade9e4aebbe84d1977ce4143343
1 /***
2 **** CAUTION!!! KEEP DOC CONSISTENT---if you change text of a message
3 **** here, change two places:
4 **** 1) the leading doc section (alphabetized by macro)
5 **** 2) the real text inside switch(errnum)
6 ***/
8 /*
9 FUNCTION
10 <<strerror>>---convert error number to string
12 INDEX
13 strerror
15 ANSI_SYNOPSIS
16 #include <string.h>
17 char *strerror(int <[errnum]>);
19 TRAD_SYNOPSIS
20 #include <string.h>
21 char *strerror(<[errnum]>)
22 int <[errnum]>;
24 DESCRIPTION
25 <<strerror>> converts the error number <[errnum]> into a
26 string. The value of <[errnum]> is usually a copy of <<errno>>.
27 If <<errnum>> is not a known error number, the result points to an
28 empty string.
30 This implementation of <<strerror>> prints out the following strings
31 for each of the values defined in `<<errno.h>>':
34 o E2BIG
35 Arg list too long
37 o EACCES
38 Permission denied
40 o EADDRINUSE
41 Address already in use
43 o EADV
44 Advertise error
46 o EAFNOSUPPORT
47 Address family not supported by protocol family
49 o EAGAIN
50 No more processes
52 o EALREADY
53 Socket already connected
55 o EBADF
56 Bad file number
58 o EBADMSG
59 Bad message
61 o EBUSY
62 Device or resource busy
64 o ECHILD
65 No children
67 o ECOMM
68 Communication error
70 o ECONNABORTED
71 Software caused connection abort
73 o ECONNREFUSED
74 Connection refused
76 o EDEADLK
77 Deadlock
79 o EDESTADDRREQ
80 Destination address required
82 o EEXIST
83 File exists
85 o EDOM
86 Math argument
88 o EFAULT
89 Bad address
91 o EFBIG
92 File too large
94 o EHOSTDOWN
95 Host is down
97 o EHOSTUNREACH
98 Host is unreachable
100 o EIDRM
101 Identifier removed
103 o EINPROGRESS
104 Connection already in progress
106 o EINTR
107 Interrupted system call
109 o EINVAL
110 Invalid argument
112 o EIO
113 I/O error
115 o EISCONN
116 Socket is already connected
118 o EISDIR
119 Is a directory
121 o ELIBACC
122 Cannot access a needed shared library
124 o ELIBBAD
125 Accessing a corrupted shared library
127 o ELIBEXEC
128 Cannot exec a shared library directly
130 o ELIBMAX
131 Attempting to link in more shared libraries than system limit
133 o ELIBSCN
134 <<.lib>> section in a.out corrupted
136 o EMFILE
137 Too many open files
139 o EMLINK
140 Too many links
142 o EMSGSIZE
143 Message too long
145 o EMULTIHOP
146 Multihop attempted
148 o ENAMETOOLONG
149 File or path name too long
151 o ENETDOWN
152 Network interface not configured
154 o ENETUNREACH
155 Network is unreachable
157 o ENFILE
158 Too many open files in system
160 o ENODEV
161 No such device
163 o ENOENT
164 No such file or directory
166 o ENOEXEC
167 Exec format error
169 o ENOLCK
170 No lock
172 o ENOLINK
173 Virtual circuit is gone
175 o ENOMEM
176 Not enough space
178 o ENOMSG
179 No message of desired type
181 o ENONET
182 Machine is not on the network
184 o ENOPKG
185 No package
187 o ENOPROTOOPT
188 Protocol not available
190 o ENOSPC
191 No space left on device
193 o ENOSR
194 No stream resources
196 o ENOSTR
197 Not a stream
199 o ENOSYS
200 Function not implemented
202 o ENOTBLK
203 Block device required
205 o ENOTCONN
206 Socket is not connected
208 o ENOTDIR
209 Not a directory
211 o ENOTEMPTY
212 Directory not empty
214 o ENOTSOCK
215 Socket operation on non-socket
217 o ENOTSUP
218 Not supported
220 o ENOTTY
221 Not a character device
223 o ENXIO
224 No such device or address
226 o EPERM
227 Not owner
229 o EPIPE
230 Broken pipe
232 o EPROTO
233 Protocol error
235 o EPROTOTYPE
236 Protocol wrong type for socket
238 o EPROTONOSUPPORT
239 Unknown protocol
241 o ERANGE
242 Result too large
244 o EREMOTE
245 Resource is remote
247 o EROFS
248 Read-only file system
250 o ESHUTDOWN
251 Can't send after socket shutdown
253 o ESOCKTNOSUPPORT
254 Socket type not supported
256 o ESPIPE
257 Illegal seek
259 o ESRCH
260 No such process
262 o ESRMNT
263 Srmount error
265 o ETIME
266 Stream ioctl timeout
268 o ETIMEDOUT
269 Connection timed out
271 o ETXTBSY
272 Text file busy
274 o EXDEV
275 Cross-device link
279 RETURNS
280 This function returns a pointer to a string. Your application must
281 not modify that string.
283 PORTABILITY
284 ANSI C requires <<strerror>>, but does not specify the strings used
285 for each error number.
287 Although this implementation of <<strerror>> is reentrant, ANSI C
288 declares that subsequent calls to <<strerror>> may overwrite the
289 result string; therefore portable code cannot depend on the reentrancy
290 of this subroutine.
292 This implementation of <<strerror>> provides for user-defined
293 extensibility. <<errno.h>> defines <[__ELASTERROR]>, which can be
294 used as a base for user-defined error values. If the user supplies a
295 routine named <<_user_strerror>>, and <[errnum]> passed to
296 <<strerror>> does not match any of the supported values,
297 <<_user_strerror>> is called with <[errnum]> as its argument.
299 <<_user_strerror>> takes one argument of type <[int]>, and returns a
300 character pointer. If <[errnum]> is unknown to <<_user_strerror>>,
301 <<_user_strerror>> returns <[NULL]>. The default <<_user_strerror>>
302 returns <[NULL]> for all input values.
304 <<strerror>> requires no supporting OS subroutines.
306 QUICKREF
307 strerror ansi pure
310 #include <errno.h>
311 #include <string.h>
313 char *
314 _DEFUN (strerror, (errnum),
315 int errnum)
317 char *error;
318 extern char *_user_strerror _PARAMS ((int));
320 switch (errnum)
322 /* go32 defines EPERM as EACCES */
323 #if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES))
324 case EPERM:
325 error = "Not owner";
326 break;
327 #endif
328 #ifdef ENOENT
329 case ENOENT:
330 error = "No such file or directory";
331 break;
332 #endif
333 #ifdef ESRCH
334 case ESRCH:
335 error = "No such process";
336 break;
337 #endif
338 #ifdef EINTR
339 case EINTR:
340 error = "Interrupted system call";
341 break;
342 #endif
343 #ifdef EIO
344 case EIO:
345 error = "I/O error";
346 break;
347 #endif
348 /* go32 defines ENXIO as ENODEV */
349 #if defined (ENXIO) && (!defined (ENODEV) || (ENXIO != ENODEV))
350 case ENXIO:
351 error = "No such device or address";
352 break;
353 #endif
354 #ifdef E2BIG
355 case E2BIG:
356 error = "Arg list too long";
357 break;
358 #endif
359 #ifdef ENOEXEC
360 case ENOEXEC:
361 error = "Exec format error";
362 break;
363 #endif
364 #ifdef EALREADY
365 case EALREADY:
366 error = "Socket already connected";
367 break;
368 #endif
369 #ifdef EBADF
370 case EBADF:
371 error = "Bad file number";
372 break;
373 #endif
374 #ifdef ECHILD
375 case ECHILD:
376 error = "No children";
377 break;
378 #endif
379 #ifdef EDESTADDRREQ
380 case EDESTADDRREQ:
381 error = "Destination address required";
382 break;
383 #endif
384 #ifdef EAGAIN
385 case EAGAIN:
386 error = "No more processes";
387 break;
388 #endif
389 #ifdef ENOMEM
390 case ENOMEM:
391 error = "Not enough space";
392 break;
393 #endif
394 #ifdef EACCES
395 case EACCES:
396 error = "Permission denied";
397 break;
398 #endif
399 #ifdef EFAULT
400 case EFAULT:
401 error = "Bad address";
402 break;
403 #endif
404 #ifdef ENOTBLK
405 case ENOTBLK:
406 error = "Block device required";
407 break;
408 #endif
409 #ifdef EBUSY
410 case EBUSY:
411 error = "Device or resource busy";
412 break;
413 #endif
414 #ifdef EEXIST
415 case EEXIST:
416 error = "File exists";
417 break;
418 #endif
419 #ifdef EXDEV
420 case EXDEV:
421 error = "Cross-device link";
422 break;
423 #endif
424 #ifdef ENODEV
425 case ENODEV:
426 error = "No such device";
427 break;
428 #endif
429 #ifdef ENOTDIR
430 case ENOTDIR:
431 error = "Not a directory";
432 break;
433 #endif
434 #ifdef EHOSTDOWN
435 case EHOSTDOWN:
436 error = "Host is down";
437 break;
438 #endif
439 #ifdef EINPROGRESS
440 case EINPROGRESS:
441 error = "Connection already in progress";
442 break;
443 #endif
444 #ifdef EISDIR
445 case EISDIR:
446 error = "Is a directory";
447 break;
448 #endif
449 #ifdef EINVAL
450 case EINVAL:
451 error = "Invalid argument";
452 break;
453 #endif
454 #ifdef ENETDOWN
455 case ENETDOWN:
456 error = "Network interface is not configured";
457 break;
458 #endif
459 #ifdef ENFILE
460 case ENFILE:
461 error = "Too many open files in system";
462 break;
463 #endif
464 #ifdef EMFILE
465 case EMFILE:
466 error = "Too many open files";
467 break;
468 #endif
469 #ifdef ENOTTY
470 case ENOTTY:
471 error = "Not a character device";
472 break;
473 #endif
474 #ifdef ETXTBSY
475 case ETXTBSY:
476 error = "Text file busy";
477 break;
478 #endif
479 #ifdef EFBIG
480 case EFBIG:
481 error = "File too large";
482 break;
483 #endif
484 #ifdef EHOSTUNREACH
485 case EHOSTUNREACH:
486 error = "Host is unreachable";
487 break;
488 #endif
489 #ifdef ENOSPC
490 case ENOSPC:
491 error = "No space left on device";
492 break;
493 #endif
494 #ifdef ENOTSUP
495 case ENOTSUP:
496 error = "Not supported";
497 break;
498 #endif
499 #ifdef ESPIPE
500 case ESPIPE:
501 error = "Illegal seek";
502 break;
503 #endif
504 #ifdef EROFS
505 case EROFS:
506 error = "Read-only file system";
507 break;
508 #endif
509 #ifdef EMLINK
510 case EMLINK:
511 error = "Too many links";
512 break;
513 #endif
514 #ifdef EPIPE
515 case EPIPE:
516 error = "Broken pipe";
517 break;
518 #endif
519 #ifdef EDOM
520 case EDOM:
521 error = "Math argument";
522 break;
523 #endif
524 #ifdef ERANGE
525 case ERANGE:
526 error = "Result too large";
527 break;
528 #endif
529 #ifdef ENOMSG
530 case ENOMSG:
531 error = "No message of desired type";
532 break;
533 #endif
534 #ifdef EIDRM
535 case EIDRM:
536 error = "Identifier removed";
537 break;
538 #endif
539 #ifdef EDEADLK
540 case EDEADLK:
541 error = "Deadlock";
542 break;
543 #endif
544 #ifdef ENETUNREACH
545 case ENETUNREACH:
546 error = "Network is unreachable";
547 break;
548 #endif
549 #ifdef ENOLCK
550 case ENOLCK:
551 error = "No lock";
552 break;
553 #endif
554 #ifdef ENOSTR
555 case ENOSTR:
556 error = "Not a stream";
557 break;
558 #endif
559 #ifdef ETIME
560 case ETIME:
561 error = "Stream ioctl timeout";
562 break;
563 #endif
564 #ifdef ENOSR
565 case ENOSR:
566 error = "No stream resources";
567 break;
568 #endif
569 #ifdef ENONET
570 case ENONET:
571 error = "Machine is not on the network";
572 break;
573 #endif
574 #ifdef ENOPKG
575 case ENOPKG:
576 error = "No package";
577 break;
578 #endif
579 #ifdef EREMOTE
580 case EREMOTE:
581 error = "Resource is remote";
582 break;
583 #endif
584 #ifdef ENOLINK
585 case ENOLINK:
586 error = "Virtual circuit is gone";
587 break;
588 #endif
589 #ifdef EADV
590 case EADV:
591 error = "Advertise error";
592 break;
593 #endif
594 #ifdef ESRMNT
595 case ESRMNT:
596 error = "Srmount error";
597 break;
598 #endif
599 #ifdef ECOMM
600 case ECOMM:
601 error = "Communication error";
602 break;
603 #endif
604 #ifdef EPROTO
605 case EPROTO:
606 error = "Protocol error";
607 break;
608 #endif
609 #ifdef EPROTONOSUPPORT
610 case EPROTONOSUPPORT:
611 error = "Unknown protocol";
612 break;
613 #endif
614 #ifdef EMULTIHOP
615 case EMULTIHOP:
616 error = "Multihop attempted";
617 break;
618 #endif
619 #ifdef EBADMSG
620 case EBADMSG:
621 error = "Bad message";
622 break;
623 #endif
624 #ifdef ELIBACC
625 case ELIBACC:
626 error = "Cannot access a needed shared library";
627 break;
628 #endif
629 #ifdef ELIBBAD
630 case ELIBBAD:
631 error = "Accessing a corrupted shared library";
632 break;
633 #endif
634 #ifdef ELIBSCN
635 case ELIBSCN:
636 error = ".lib section in a.out corrupted";
637 break;
638 #endif
639 #ifdef ELIBMAX
640 case ELIBMAX:
641 error = "Attempting to link in more shared libraries than system limit";
642 break;
643 #endif
644 #ifdef ELIBEXEC
645 case ELIBEXEC:
646 error = "Cannot exec a shared library directly";
647 break;
648 #endif
649 #ifdef ENOSYS
650 case ENOSYS:
651 error = "Function not implemented";
652 break;
653 #endif
654 #ifdef ENMFILE
655 case ENMFILE:
656 error = "No more files";
657 break;
658 #endif
659 #ifdef ENOTEMPTY
660 case ENOTEMPTY:
661 error = "Directory not empty";
662 break;
663 #endif
664 #ifdef ENAMETOOLONG
665 case ENAMETOOLONG:
666 error = "File or path name too long";
667 break;
668 #endif
669 #ifdef ELOOP
670 case ELOOP:
671 error = "Too many symbolic links";
672 break;
673 #endif
674 #ifdef ENOBUFS
675 case ENOBUFS:
676 error = "No buffer space available";
677 break;
678 #endif
679 #ifdef EAFNOSUPPORT
680 case EAFNOSUPPORT:
681 error = "Address family not supported by protocol family";
682 break;
683 #endif
684 #ifdef EPROTOTYPE
685 case EPROTOTYPE:
686 error = "Protocol wrong type for socket";
687 break;
688 #endif
689 #ifdef ENOTSOCK
690 case ENOTSOCK:
691 error = "Socket operation on non-socket";
692 break;
693 #endif
694 #ifdef ENOPROTOOPT
695 case ENOPROTOOPT:
696 error = "Protocol not available";
697 break;
698 #endif
699 #ifdef ESHUTDOWN
700 case ESHUTDOWN:
701 error = "Can't send after socket shutdown";
702 break;
703 #endif
704 #ifdef ECONNREFUSED
705 case ECONNREFUSED:
706 error = "Connection refused";
707 break;
708 #endif
709 #ifdef EADDRINUSE
710 case EADDRINUSE:
711 error = "Address already in use";
712 break;
713 #endif
714 #ifdef ECONNABORTED
715 case ECONNABORTED:
716 error = "Software caused connection abort";
717 break;
718 #endif
719 #if (defined(EWOULDBLOCK) && (!defined (EAGAIN) || (EWOULDBLOCK != EAGAIN)))
720 case EWOULDBLOCK:
721 error = "Operation would block";
722 break;
723 #endif
724 #ifdef ENOTCONN
725 case ENOTCONN:
726 error = "Socket is not connected";
727 break;
728 #endif
729 #ifdef ESOCKTNOSUPPORT
730 case ESOCKTNOSUPPORT:
731 error = "Socket type not supported";
732 break;
733 #endif
734 #ifdef EISCONN
735 case EISCONN:
736 error = "Socket is already connected";
737 break;
738 #endif
739 #if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP))
740 case EOPNOTSUPP:
741 error = "Operation not supported on socket";
742 break;
743 #endif
744 #ifdef EMSGSIZE
745 case EMSGSIZE:
746 error = "Message too long";
747 break;
748 #endif
749 #ifdef ETIMEDOUT
750 case ETIMEDOUT:
751 error = "Connection timed out";
752 break;
753 #endif
754 default:
755 if ((error = _user_strerror (errnum)) == 0)
756 error = "";
757 break;
760 return error;