Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / string / strerror.c
blob8f961d3b5ddaf263754066296afdb89e4cf67c35
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>>, <<strerror_l>>---convert error number to string
12 INDEX
13 strerror
15 INDEX
16 strerror_l
18 SYNOPSIS
19 #include <string.h>
20 char *strerror(int <[errnum]>);
21 char *strerror_l(int <[errnum]>, locale_t <[locale]>);
22 char *_strerror_r(struct _reent <[ptr]>, int <[errnum]>,
23 int <[internal]>, int *<[error]>);
25 DESCRIPTION
26 <<strerror>> converts the error number <[errnum]> into a
27 string. The value of <[errnum]> is usually a copy of <<errno>>.
28 If <<errnum>> is not a known error number, the result points to an
29 empty string.
31 <<strerror_l>> is like <<strerror>> but creates a string in a format
32 as expected in locale <[locale]>. If <[locale]> is LC_GLOBAL_LOCALE or
33 not a valid locale object, the behaviour is undefined.
35 This implementation of <<strerror>> prints out the following strings
36 for each of the values defined in `<<errno.h>>':
39 o 0
40 Success
42 o E2BIG
43 Arg list too long
45 o EACCES
46 Permission denied
48 o EADDRINUSE
49 Address already in use
51 o EADDRNOTAVAIL
52 Address not available
54 o EADV
55 Advertise error
57 o EAFNOSUPPORT
58 Address family not supported by protocol family
60 o EAGAIN
61 No more processes
63 o EALREADY
64 Socket already connected
66 o EBADF
67 Bad file number
69 o EBADMSG
70 Bad message
72 o EBUSY
73 Device or resource busy
75 o ECANCELED
76 Operation canceled
78 o ECHILD
79 No children
81 o ECOMM
82 Communication error
84 o ECONNABORTED
85 Software caused connection abort
87 o ECONNREFUSED
88 Connection refused
90 o ECONNRESET
91 Connection reset by peer
93 o EDEADLK
94 Deadlock
96 o EDESTADDRREQ
97 Destination address required
99 o EEXIST
100 File exists
102 o EDOM
103 Mathematics argument out of domain of function
105 o EFAULT
106 Bad address
108 o EFBIG
109 File too large
111 o EHOSTDOWN
112 Host is down
114 o EHOSTUNREACH
115 Host is unreachable
117 o EIDRM
118 Identifier removed
120 o EILSEQ
121 Illegal byte sequence
123 o EINPROGRESS
124 Connection already in progress
126 o EINTR
127 Interrupted system call
129 o EINVAL
130 Invalid argument
132 o EIO
133 I/O error
135 o EISCONN
136 Socket is already connected
138 o EISDIR
139 Is a directory
141 o ELIBACC
142 Cannot access a needed shared library
144 o ELIBBAD
145 Accessing a corrupted shared library
147 o ELIBEXEC
148 Cannot exec a shared library directly
150 o ELIBMAX
151 Attempting to link in more shared libraries than system limit
153 o ELIBSCN
154 <<.lib>> section in a.out corrupted
156 o EMFILE
157 File descriptor value too large
159 o EMLINK
160 Too many links
162 o EMSGSIZE
163 Message too long
165 o EMULTIHOP
166 Multihop attempted
168 o ENAMETOOLONG
169 File or path name too long
171 o ENETDOWN
172 Network interface is not configured
174 o ENETRESET
175 Connection aborted by network
177 o ENETUNREACH
178 Network is unreachable
180 o ENFILE
181 Too many open files in system
183 o ENOBUFS
184 No buffer space available
186 o ENODATA
187 No data
189 o ENODEV
190 No such device
192 o ENOENT
193 No such file or directory
195 o ENOEXEC
196 Exec format error
198 o ENOLCK
199 No lock
201 o ENOLINK
202 Virtual circuit is gone
204 o ENOMEM
205 Not enough space
207 o ENOMSG
208 No message of desired type
210 o ENONET
211 Machine is not on the network
213 o ENOPKG
214 No package
216 o ENOPROTOOPT
217 Protocol not available
219 o ENOSPC
220 No space left on device
222 o ENOSR
223 No stream resources
225 o ENOSTR
226 Not a stream
228 o ENOSYS
229 Function not implemented
231 o ENOTBLK
232 Block device required
234 o ENOTCONN
235 Socket is not connected
237 o ENOTDIR
238 Not a directory
240 o ENOTEMPTY
241 Directory not empty
243 o ENOTRECOVERABLE
244 State not recoverable
246 o ENOTSOCK
247 Socket operation on non-socket
249 o ENOTSUP
250 Not supported
252 o ENOTTY
253 Not a character device
255 o ENXIO
256 No such device or address
258 o EOPNOTSUPP
259 Operation not supported on socket
261 o EOVERFLOW
262 Value too large for defined data type
264 o EOWNERDEAD
265 Previous owner died
267 o EPERM
268 Not owner
270 o EPIPE
271 Broken pipe
273 o EPROTO
274 Protocol error
276 o EPROTOTYPE
277 Protocol wrong type for socket
279 o EPROTONOSUPPORT
280 Unknown protocol
282 o ERANGE
283 Result too large
285 o EREMOTE
286 Resource is remote
288 o EROFS
289 Read-only file system
291 o ESHUTDOWN
292 Can't send after socket shutdown
294 o ESOCKTNOSUPPORT
295 Socket type not supported
297 o ESPIPE
298 Illegal seek
300 o ESRCH
301 No such process
303 o ESRMNT
304 Srmount error
306 o ESTRPIPE
307 Strings pipe error
309 o ETIME
310 Stream ioctl timeout
312 o ETIMEDOUT
313 Connection timed out
315 o ETXTBSY
316 Text file busy
318 o EWOULDBLOCK
319 Operation would block (usually same as EAGAIN)
321 o EXDEV
322 Cross-device link
326 <<_strerror_r>> is a reentrant version of the above.
328 RETURNS
329 This function returns a pointer to a string. Your application must
330 not modify that string.
332 PORTABILITY
333 ANSI C requires <<strerror>>, but does not specify the strings used
334 for each error number.
336 <<strerror_l>> is POSIX-1.2008.
338 Although this implementation of <<strerror>> is reentrant (depending
339 on <<_user_strerror>>), ANSI C declares that subsequent calls to
340 <<strerror>> may overwrite the result string; therefore portable
341 code cannot depend on the reentrancy of this subroutine.
343 Although this implementation of <<strerror>> guarantees a non-null
344 result with a NUL-terminator, some implementations return <<NULL>>
345 on failure. Although POSIX allows <<strerror>> to set <<errno>>
346 to EINVAL on failure, this implementation does not do so (unless
347 you provide <<_user_strerror>>).
349 POSIX recommends that unknown <[errnum]> result in a message
350 including that value, however it is not a requirement and this
351 implementation does not provide that information (unless you
352 provide <<_user_strerror>>).
354 This implementation of <<strerror>> provides for user-defined
355 extensibility. <<errno.h>> defines <[__ELASTERROR]>, which can be
356 used as a base for user-defined error values. If the user supplies a
357 routine named <<_user_strerror>>, and <[errnum]> passed to
358 <<strerror>> does not match any of the supported values,
359 <<_user_strerror>> is called with three arguments. The first is of
360 type <[int]>, and is the <[errnum]> value unknown to <<strerror>>.
361 The second is of type <[int]>, and matches the <[internal]> argument
362 of <<_strerror_r>>; this should be zero if called from <<strerror>>
363 and non-zero if called from any other function; <<_user_strerror>> can
364 use this information to satisfy the POSIX rule that no other
365 standardized function can overwrite a static buffer reused by
366 <<strerror>>. The third is of type <[int *]>, and matches the
367 <[error]> argument of <<_strerror_r>>; if a non-zero value is stored
368 into that location (usually <[EINVAL]>), then <<strerror>> will set
369 <<errno>> to that value, and the XPG variant of <<strerror_r>> will
370 return that value instead of zero or <[ERANGE]>. <<_user_strerror>>
371 returns a <[char *]> value; returning <[NULL]> implies that the user
372 function did not choose to handle <[errnum]>. The default
373 <<_user_strerror>> returns <[NULL]> for all input values. Note that
374 <<_user_sterror>> must be thread-safe, and only denote errors via the
375 third argument rather than modifying <<errno>>, if <<strerror>> and
376 <<strerror_r>> are are to comply with POSIX.
378 <<strerror>> requires no supporting OS subroutines.
380 QUICKREF
381 strerror ansi pure
384 #include <errno.h>
385 #include <string.h>
387 char *
388 _strerror_r (struct _reent *ptr,
389 int errnum,
390 int internal,
391 int *errptr)
393 char *error;
394 extern char *_user_strerror (int, int, int *);
396 switch (errnum)
398 case 0:
399 error = "Success";
400 break;
401 /* go32 defines EPERM as EACCES */
402 #if defined (EPERM) && (!defined (EACCES) || (EPERM != EACCES))
403 case EPERM:
404 error = "Not owner";
405 break;
406 #endif
407 #ifdef ENOENT
408 case ENOENT:
409 error = "No such file or directory";
410 break;
411 #endif
412 #ifdef ESRCH
413 case ESRCH:
414 error = "No such process";
415 break;
416 #endif
417 #ifdef EINTR
418 case EINTR:
419 error = "Interrupted system call";
420 break;
421 #endif
422 #ifdef EIO
423 case EIO:
424 error = "I/O error";
425 break;
426 #endif
427 /* go32 defines ENXIO as ENODEV */
428 #if defined (ENXIO) && (!defined (ENODEV) || (ENXIO != ENODEV))
429 case ENXIO:
430 error = "No such device or address";
431 break;
432 #endif
433 #ifdef E2BIG
434 case E2BIG:
435 error = "Arg list too long";
436 break;
437 #endif
438 #ifdef ENOEXEC
439 case ENOEXEC:
440 error = "Exec format error";
441 break;
442 #endif
443 #ifdef EALREADY
444 case EALREADY:
445 error = "Socket already connected";
446 break;
447 #endif
448 #ifdef EBADF
449 case EBADF:
450 error = "Bad file number";
451 break;
452 #endif
453 #ifdef ECHILD
454 case ECHILD:
455 error = "No children";
456 break;
457 #endif
458 #ifdef EDESTADDRREQ
459 case EDESTADDRREQ:
460 error = "Destination address required";
461 break;
462 #endif
463 #ifdef EAGAIN
464 case EAGAIN:
465 error = "No more processes";
466 break;
467 #endif
468 #ifdef ENOMEM
469 case ENOMEM:
470 error = "Not enough space";
471 break;
472 #endif
473 #ifdef EACCES
474 case EACCES:
475 error = "Permission denied";
476 break;
477 #endif
478 #ifdef EFAULT
479 case EFAULT:
480 error = "Bad address";
481 break;
482 #endif
483 #ifdef ENOTBLK
484 case ENOTBLK:
485 error = "Block device required";
486 break;
487 #endif
488 #ifdef EBUSY
489 case EBUSY:
490 error = "Device or resource busy";
491 break;
492 #endif
493 #ifdef EEXIST
494 case EEXIST:
495 error = "File exists";
496 break;
497 #endif
498 #ifdef EXDEV
499 case EXDEV:
500 error = "Cross-device link";
501 break;
502 #endif
503 #ifdef ENODEV
504 case ENODEV:
505 error = "No such device";
506 break;
507 #endif
508 #ifdef ENOTDIR
509 case ENOTDIR:
510 error = "Not a directory";
511 break;
512 #endif
513 #ifdef EHOSTDOWN
514 case EHOSTDOWN:
515 error = "Host is down";
516 break;
517 #endif
518 #ifdef EINPROGRESS
519 case EINPROGRESS:
520 error = "Connection already in progress";
521 break;
522 #endif
523 #ifdef EISDIR
524 case EISDIR:
525 error = "Is a directory";
526 break;
527 #endif
528 #ifdef EINVAL
529 case EINVAL:
530 error = "Invalid argument";
531 break;
532 #endif
533 #ifdef ENETDOWN
534 case ENETDOWN:
535 error = "Network interface is not configured";
536 break;
537 #endif
538 #ifdef ENETRESET
539 case ENETRESET:
540 error = "Connection aborted by network";
541 break;
542 #endif
543 #ifdef ENFILE
544 case ENFILE:
545 error = "Too many open files in system";
546 break;
547 #endif
548 #ifdef EMFILE
549 case EMFILE:
550 error = "File descriptor value too large";
551 break;
552 #endif
553 #ifdef ENOTTY
554 case ENOTTY:
555 error = "Not a character device";
556 break;
557 #endif
558 #ifdef ETXTBSY
559 case ETXTBSY:
560 error = "Text file busy";
561 break;
562 #endif
563 #ifdef EFBIG
564 case EFBIG:
565 error = "File too large";
566 break;
567 #endif
568 #ifdef EHOSTUNREACH
569 case EHOSTUNREACH:
570 error = "Host is unreachable";
571 break;
572 #endif
573 #ifdef ENOSPC
574 case ENOSPC:
575 error = "No space left on device";
576 break;
577 #endif
578 #ifdef ENOTSUP
579 case ENOTSUP:
580 error = "Not supported";
581 break;
582 #endif
583 #ifdef ESPIPE
584 case ESPIPE:
585 error = "Illegal seek";
586 break;
587 #endif
588 #ifdef EROFS
589 case EROFS:
590 error = "Read-only file system";
591 break;
592 #endif
593 #ifdef EMLINK
594 case EMLINK:
595 error = "Too many links";
596 break;
597 #endif
598 #ifdef EPIPE
599 case EPIPE:
600 error = "Broken pipe";
601 break;
602 #endif
603 #ifdef EDOM
604 case EDOM:
605 error = "Mathematics argument out of domain of function";
606 break;
607 #endif
608 #ifdef ERANGE
609 case ERANGE:
610 error = "Result too large";
611 break;
612 #endif
613 #ifdef ENOMSG
614 case ENOMSG:
615 error = "No message of desired type";
616 break;
617 #endif
618 #ifdef EIDRM
619 case EIDRM:
620 error = "Identifier removed";
621 break;
622 #endif
623 #ifdef EILSEQ
624 case EILSEQ:
625 error = "Illegal byte sequence";
626 break;
627 #endif
628 #ifdef EDEADLK
629 case EDEADLK:
630 error = "Deadlock";
631 break;
632 #endif
633 #ifdef ENETUNREACH
634 case ENETUNREACH:
635 error = "Network is unreachable";
636 break;
637 #endif
638 #ifdef ENOLCK
639 case ENOLCK:
640 error = "No lock";
641 break;
642 #endif
643 #ifdef ENOSTR
644 case ENOSTR:
645 error = "Not a stream";
646 break;
647 #endif
648 #ifdef ETIME
649 case ETIME:
650 error = "Stream ioctl timeout";
651 break;
652 #endif
653 #ifdef ENOSR
654 case ENOSR:
655 error = "No stream resources";
656 break;
657 #endif
658 #ifdef ENONET
659 case ENONET:
660 error = "Machine is not on the network";
661 break;
662 #endif
663 #ifdef ENOPKG
664 case ENOPKG:
665 error = "No package";
666 break;
667 #endif
668 #ifdef EREMOTE
669 case EREMOTE:
670 error = "Resource is remote";
671 break;
672 #endif
673 #ifdef ENOLINK
674 case ENOLINK:
675 error = "Virtual circuit is gone";
676 break;
677 #endif
678 #ifdef EADV
679 case EADV:
680 error = "Advertise error";
681 break;
682 #endif
683 #ifdef ESRMNT
684 case ESRMNT:
685 error = "Srmount error";
686 break;
687 #endif
688 #ifdef ECOMM
689 case ECOMM:
690 error = "Communication error";
691 break;
692 #endif
693 #ifdef EPROTO
694 case EPROTO:
695 error = "Protocol error";
696 break;
697 #endif
698 #ifdef EPROTONOSUPPORT
699 case EPROTONOSUPPORT:
700 error = "Unknown protocol";
701 break;
702 #endif
703 #ifdef EMULTIHOP
704 case EMULTIHOP:
705 error = "Multihop attempted";
706 break;
707 #endif
708 #ifdef EBADMSG
709 case EBADMSG:
710 error = "Bad message";
711 break;
712 #endif
713 #ifdef ELIBACC
714 case ELIBACC:
715 error = "Cannot access a needed shared library";
716 break;
717 #endif
718 #ifdef ELIBBAD
719 case ELIBBAD:
720 error = "Accessing a corrupted shared library";
721 break;
722 #endif
723 #ifdef ELIBSCN
724 case ELIBSCN:
725 error = ".lib section in a.out corrupted";
726 break;
727 #endif
728 #ifdef ELIBMAX
729 case ELIBMAX:
730 error = "Attempting to link in more shared libraries than system limit";
731 break;
732 #endif
733 #ifdef ELIBEXEC
734 case ELIBEXEC:
735 error = "Cannot exec a shared library directly";
736 break;
737 #endif
738 #ifdef ENOSYS
739 case ENOSYS:
740 error = "Function not implemented";
741 break;
742 #endif
743 #ifdef ENMFILE
744 case ENMFILE:
745 error = "No more files";
746 break;
747 #endif
748 #ifdef ENOTEMPTY
749 case ENOTEMPTY:
750 error = "Directory not empty";
751 break;
752 #endif
753 #ifdef ENAMETOOLONG
754 case ENAMETOOLONG:
755 error = "File or path name too long";
756 break;
757 #endif
758 #ifdef ELOOP
759 case ELOOP:
760 error = "Too many symbolic links";
761 break;
762 #endif
763 #ifdef ENOBUFS
764 case ENOBUFS:
765 error = "No buffer space available";
766 break;
767 #endif
768 #ifdef ENODATA
769 case ENODATA:
770 error = "No data";
771 break;
772 #endif
773 #ifdef EAFNOSUPPORT
774 case EAFNOSUPPORT:
775 error = "Address family not supported by protocol family";
776 break;
777 #endif
778 #ifdef EPROTOTYPE
779 case EPROTOTYPE:
780 error = "Protocol wrong type for socket";
781 break;
782 #endif
783 #ifdef ENOTSOCK
784 case ENOTSOCK:
785 error = "Socket operation on non-socket";
786 break;
787 #endif
788 #ifdef ENOPROTOOPT
789 case ENOPROTOOPT:
790 error = "Protocol not available";
791 break;
792 #endif
793 #ifdef ESHUTDOWN
794 case ESHUTDOWN:
795 error = "Can't send after socket shutdown";
796 break;
797 #endif
798 #ifdef ECONNREFUSED
799 case ECONNREFUSED:
800 error = "Connection refused";
801 break;
802 #endif
803 #ifdef ECONNRESET
804 case ECONNRESET:
805 error = "Connection reset by peer";
806 break;
807 #endif
808 #ifdef EADDRINUSE
809 case EADDRINUSE:
810 error = "Address already in use";
811 break;
812 #endif
813 #ifdef EADDRNOTAVAIL
814 case EADDRNOTAVAIL:
815 error = "Address not available";
816 break;
817 #endif
818 #ifdef ECONNABORTED
819 case ECONNABORTED:
820 error = "Software caused connection abort";
821 break;
822 #endif
823 #if (defined(EWOULDBLOCK) && (!defined (EAGAIN) || (EWOULDBLOCK != EAGAIN)))
824 case EWOULDBLOCK:
825 error = "Operation would block";
826 break;
827 #endif
828 #ifdef ENOTCONN
829 case ENOTCONN:
830 error = "Socket is not connected";
831 break;
832 #endif
833 #ifdef ESOCKTNOSUPPORT
834 case ESOCKTNOSUPPORT:
835 error = "Socket type not supported";
836 break;
837 #endif
838 #ifdef EISCONN
839 case EISCONN:
840 error = "Socket is already connected";
841 break;
842 #endif
843 #ifdef ECANCELED
844 case ECANCELED:
845 error = "Operation canceled";
846 break;
847 #endif
848 #ifdef ENOTRECOVERABLE
849 case ENOTRECOVERABLE:
850 error = "State not recoverable";
851 break;
852 #endif
853 #ifdef EOWNERDEAD
854 case EOWNERDEAD:
855 error = "Previous owner died";
856 break;
857 #endif
858 #ifdef ESTRPIPE
859 case ESTRPIPE:
860 error = "Streams pipe error";
861 break;
862 #endif
863 #if defined(EOPNOTSUPP) && (!defined(ENOTSUP) || (ENOTSUP != EOPNOTSUPP))
864 case EOPNOTSUPP:
865 error = "Operation not supported on socket";
866 break;
867 #endif
868 #ifdef EOVERFLOW
869 case EOVERFLOW:
870 error = "Value too large for defined data type";
871 break;
872 #endif
873 #ifdef EMSGSIZE
874 case EMSGSIZE:
875 error = "Message too long";
876 break;
877 #endif
878 #ifdef ETIMEDOUT
879 case ETIMEDOUT:
880 error = "Connection timed out";
881 break;
882 #endif
883 default:
884 if (!errptr)
885 errptr = &_REENT_ERRNO(ptr);
886 if ((error = _user_strerror (errnum, internal, errptr)) == 0)
887 error = "";
888 break;
891 return error;
894 char *
895 strerror (int errnum)
897 return _strerror_r (_REENT, errnum, 0, NULL);
900 char *
901 strerror_l (int errnum, locale_t locale)
903 /* We don't support per-locale error messages. */
904 return _strerror_r (_REENT, errnum, 0, NULL);