source: trunk/libs/newlib/src/newlib/libc/string/strerror.c @ 577

Last change on this file since 577 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 16.5 KB
Line 
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***/
7
8/*
9FUNCTION
10        <<strerror>>, <<strerror_l>>---convert error number to string
11
12INDEX
13        strerror
14
15INDEX
16        strerror_l
17
18SYNOPSIS
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]>);
24
25DESCRIPTION
26<<strerror>> converts the error number <[errnum]> into a
27string.  The value of <[errnum]> is usually a copy of <<errno>>.
28If <<errnum>> is not a known error number, the result points to an
29empty string.
30
31<<strerror_l>> is like <<strerror>> but creates a string in a format
32as expected in locale <[locale]>.  If <[locale]> is LC_GLOBAL_LOCALE or
33not a valid locale object, the behaviour is undefined.
34
35This implementation of <<strerror>> prints out the following strings
36for each of the values defined in `<<errno.h>>':
37
38o+
39o 0
40Success
41
42o E2BIG
43Arg list too long
44
45o EACCES
46Permission denied
47
48o EADDRINUSE
49Address already in use
50
51o EADDRNOTAVAIL
52Address not available
53
54o EADV
55Advertise error
56
57o EAFNOSUPPORT
58Address family not supported by protocol family
59
60o EAGAIN
61No more processes
62
63o EALREADY
64Socket already connected
65
66o EBADF
67Bad file number
68
69o EBADMSG
70Bad message
71
72o EBUSY
73Device or resource busy
74
75o ECANCELED
76Operation canceled
77
78o ECHILD
79No children
80
81o ECOMM
82Communication error
83
84o ECONNABORTED
85Software caused connection abort
86
87o ECONNREFUSED
88Connection refused
89
90o ECONNRESET
91Connection reset by peer
92
93o EDEADLK
94Deadlock
95
96o EDESTADDRREQ
97Destination address required
98
99o EEXIST
100File exists
101
102o EDOM
103Mathematics argument out of domain of function
104
105o EFAULT
106Bad address
107
108o EFBIG
109File too large
110
111o EHOSTDOWN
112Host is down
113
114o EHOSTUNREACH
115Host is unreachable
116
117o EIDRM
118Identifier removed
119
120o EILSEQ
121Illegal byte sequence
122
123o EINPROGRESS
124Connection already in progress
125
126o EINTR
127Interrupted system call
128
129o EINVAL
130Invalid argument
131
132o EIO
133I/O error
134
135o EISCONN
136Socket is already connected
137
138o EISDIR
139Is a directory
140
141o ELIBACC
142Cannot access a needed shared library
143
144o ELIBBAD
145Accessing a corrupted shared library
146
147o ELIBEXEC
148Cannot exec a shared library directly
149
150o ELIBMAX
151Attempting to link in more shared libraries than system limit
152
153o ELIBSCN
154<<.lib>> section in a.out corrupted
155
156o EMFILE
157File descriptor value too large
158
159o EMLINK
160Too many links
161
162o EMSGSIZE
163Message too long
164
165o EMULTIHOP
166Multihop attempted
167
168o ENAMETOOLONG
169File or path name too long
170
171o ENETDOWN
172Network interface is not configured
173
174o ENETRESET
175Connection aborted by network
176
177o ENETUNREACH
178Network is unreachable
179
180o ENFILE
181Too many open files in system
182
183o ENOBUFS
184No buffer space available
185
186o ENODATA
187No data
188
189o ENODEV
190No such device
191
192o ENOENT
193No such file or directory
194
195o ENOEXEC
196Exec format error
197
198o ENOLCK
199No lock
200
201o ENOLINK
202Virtual circuit is gone
203
204o ENOMEM
205Not enough space
206
207o ENOMSG
208No message of desired type
209
210o ENONET
211Machine is not on the network
212
213o ENOPKG
214No package
215
216o ENOPROTOOPT
217Protocol not available
218
219o ENOSPC
220No space left on device
221
222o ENOSR
223No stream resources
224
225o ENOSTR
226Not a stream
227
228o ENOSYS
229Function not implemented
230
231o ENOTBLK
232Block device required
233
234o ENOTCONN
235Socket is not connected
236
237o ENOTDIR
238Not a directory
239
240o ENOTEMPTY
241Directory not empty
242
243o ENOTRECOVERABLE
244State not recoverable
245
246o ENOTSOCK
247Socket operation on non-socket
248
249o ENOTSUP
250Not supported
251
252o ENOTTY
253Not a character device
254
255o ENXIO
256No such device or address
257
258o EOPNOTSUPP
259Operation not supported on socket
260
261o EOVERFLOW
262Value too large for defined data type
263
264o EOWNERDEAD
265Previous owner died
266
267o EPERM
268Not owner
269
270o EPIPE
271Broken pipe
272
273o EPROTO
274Protocol error
275
276o EPROTOTYPE
277Protocol wrong type for socket
278
279o EPROTONOSUPPORT
280Unknown protocol
281
282o ERANGE
283Result too large
284
285o EREMOTE
286Resource is remote
287
288o EROFS
289Read-only file system
290
291o ESHUTDOWN
292Can't send after socket shutdown
293
294o ESOCKTNOSUPPORT
295Socket type not supported
296
297o ESPIPE
298Illegal seek
299
300o ESRCH
301No such process
302
303o ESRMNT
304Srmount error
305
306o ESTRPIPE
307Strings pipe error
308
309o ETIME
310Stream ioctl timeout
311
312o ETIMEDOUT
313Connection timed out
314
315o ETXTBSY
316Text file busy
317
318o EWOULDBLOCK
319Operation would block (usually same as EAGAIN)
320
321o EXDEV
322Cross-device link
323
324o-
325
326<<_strerror_r>> is a reentrant version of the above.
327
328RETURNS
329This function returns a pointer to a string.  Your application must
330not modify that string.
331
332PORTABILITY
333ANSI C requires <<strerror>>, but does not specify the strings used
334for each error number.
335
336<<strerror_l>> is POSIX-1.2008.
337
338Although this implementation of <<strerror>> is reentrant (depending
339on <<_user_strerror>>), ANSI C declares that subsequent calls to
340<<strerror>> may overwrite the result string; therefore portable
341code cannot depend on the reentrancy of this subroutine.
342
343Although this implementation of <<strerror>> guarantees a non-null
344result with a NUL-terminator, some implementations return <<NULL>>
345on failure.  Although POSIX allows <<strerror>> to set <<errno>>
346to EINVAL on failure, this implementation does not do so (unless
347you provide <<_user_strerror>>).
348
349POSIX recommends that unknown <[errnum]> result in a message
350including that value, however it is not a requirement and this
351implementation does not provide that information (unless you
352provide <<_user_strerror>>).
353
354This implementation of <<strerror>> provides for user-defined
355extensibility.  <<errno.h>> defines <[__ELASTERROR]>, which can be
356used as a base for user-defined error values.  If the user supplies a
357routine 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
360type <[int]>, and is the <[errnum]> value unknown to <<strerror>>.
361The second is of type <[int]>, and matches the <[internal]> argument
362of <<_strerror_r>>; this should be zero if called from <<strerror>>
363and non-zero if called from any other function; <<_user_strerror>> can
364use this information to satisfy the POSIX rule that no other
365standardized 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
368into that location (usually <[EINVAL]>), then <<strerror>> will set
369<<errno>> to that value, and the XPG variant of <<strerror_r>> will
370return that value instead of zero or <[ERANGE]>.  <<_user_strerror>>
371returns a <[char *]> value; returning <[NULL]> implies that the user
372function 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
375third argument rather than modifying <<errno>>, if <<strerror>> and
376<<strerror_r>> are are to comply with POSIX.
377
378<<strerror>> requires no supporting OS subroutines.
379
380QUICKREF
381        strerror ansi pure
382*/
383
384#include <errno.h>
385#include <string.h>
386
387char *
388_strerror_r (struct _reent *ptr,
389        int errnum,
390        int internal,
391        int *errptr)
392{
393  char *error;
394  extern char *_user_strerror (int, int, int *);
395
396  switch (errnum)
397    {
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 = &ptr->_errno;
886      if ((error = _user_strerror (errnum, internal, errptr)) == 0)
887        error = "";
888      break;
889    }
890
891  return error;
892}
893
894char *
895strerror (int errnum)
896{
897  return _strerror_r (_REENT, errnum, 0, NULL);
898}
899
900char *
901strerror_l (int errnum, locale_t locale)
902{
903  /* We don't support per-locale error messages. */
904  return _strerror_r (_REENT, errnum, 0, NULL);
905}
Note: See TracBrowser for help on using the repository browser.