Enabled some keys which need the alt qualifier (brackets, back slash etc.)
[AROS.git] / compiler / stdc / strerror.c
blob7df1b03aba8928860adee7e8dbac9d8f75ba888b
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function strerror().
6 */
8 #include "__stdc_intbase.h"
10 #include <proto/dos.h>
11 #include <clib/macros.h>
12 #include <stdlib.h>
13 #include <errno.h>
15 static const char * _errstrings[];
17 /*****************************************************************************
19 NAME
20 #include <string.h>
22 char * strerror (
24 SYNOPSIS
25 int n)
27 FUNCTION
28 Returns a readable string for an error number in errno.
30 INPUTS
31 n - The contents of errno or a #define from errno.h
33 RESULT
34 A string describing the error.
36 NOTES
38 EXAMPLE
40 BUGS
42 SEE ALSO
43 __stdc_strerror()
45 INTERNALS
47 ******************************************************************************/
49 /*****************************************************************************
51 NAME */
52 #include <string.h>
54 char * __stdc_strerror (
56 /* SYNOPSIS */
57 int n)
59 /* FUNCTION
60 Returns a readable string for an error number in errno.
62 INPUTS
63 n - The contents of errno or a #define from errno.h
65 RESULT
66 A string describing the error.
68 NOTES
69 This functions only handles the error codes needed by C99 and the ones
70 used in stdc.library. This function is aliased as strerror() in
71 libstdc.a
72 Other libraries may override this function by providing this function
73 also in their libxxx.a file. They can internally call __stdc_strerror
74 to get the strings for the errors handled by this function.
76 EXAMPLE
78 BUGS
80 SEE ALSO
81 strerror()
83 INTERNALS
85 ******************************************************************************/
87 if (n > MAX_ERRNO)
89 struct StdCIntBase *StdCBase =
90 (struct StdCIntBase *)__aros_getbase_StdCBase();
92 if (StdCBase->fault_buf == NULL)
93 /* This is not freed anywhere, will be cleaned when
94 libbase is expunged
96 StdCBase->fault_buf = malloc(100);
98 Fault(n - MAX_ERRNO, NULL, StdCBase->fault_buf, 100);
100 return StdCBase->fault_buf;
102 else
104 char *s;
106 s = (char *)_errstrings[MIN(n, __STDC_ELAST+1)];
108 if (s == NULL)
109 s = (char *)"Errno out of range";
111 return s;
113 } /* strerror */
116 static const char * _errstrings[__STDC_ELAST+2] =
118 /* 0 */ "No error",
119 /* NA */ NULL,
120 /* ENOENT */ "No such file or directory",
121 /* NA */ NULL,
122 /* EINTR */ "Interrupted system call",
123 /* NA */ NULL,
124 /* NA */ NULL,
125 /* NA */ NULL,
126 /* ENOEXEC */ "Exec format error",
127 /* NA */ NULL,
128 /* NA */ NULL,
129 /* NA */ NULL,
130 /* ENOMEM */ "Out of memory",
131 /* EACCES */ "Permission denied",
132 /* NA */ NULL,
133 /* NA */ NULL,
134 /* EBUSY */ "Device or resource busy",
135 /* EEXIST */ "File exists",
136 /* EXDEV */ "Cross-device link",
137 /* NA */ NULL,
138 /* ENOTDIR */ "Not a directory",
139 /* NA */ NULL,
140 /* EINVAL */ "Invalid argument",
141 /* NA */ NULL,
142 /* NA */ NULL,
143 /* NA */ NULL,
144 /* NA */ NULL,
145 /* NA */ NULL,
146 /* NA */ NULL,
147 /* NA */ NULL,
148 /* NA */ NULL,
149 /* NA */ NULL,
150 /* NA */ NULL,
151 /* EDOM */ "Numerical argument out of domain",
152 /* ERANGE */ "Math result not representable",
153 /* NA */ NULL,
154 /* NA */ NULL,
155 /* NA */ NULL,
156 /* NA */ NULL,
157 /* NA */ NULL,
158 /* NA */ NULL,
159 /* NA */ NULL,
160 /* NA */ NULL,
161 /* NA */ NULL,
162 /* NA */ NULL,
163 /* NA */ NULL,
164 /* NA */ NULL,
165 /* NA */ NULL,
166 /* NA */ NULL,
167 /* NA */ NULL,
168 /* NA */ NULL,
169 /* NA */ NULL,
170 /* NA */ NULL,
171 /* NA */ NULL,
172 /* NA */ NULL,
173 /* ENOBUFS */ "No buffer space available",
174 /* NA */ NULL,
175 /* NA */ NULL,
176 /* NA */ NULL,
177 /* NA */ NULL,
178 /* NA */ NULL,
179 /* NA */ NULL,
180 /* NA */ NULL,
181 /* NA */ NULL,
182 /* NA */ NULL,
183 /* NA */ NULL,
184 /* NA */ NULL,
185 /* NA */ NULL,
186 /* NA */ NULL,
187 /* NA */ NULL,
188 /* NA */ NULL,
189 /* NA */ NULL,
190 /* NA */ NULL,
191 /* NA */ NULL,
192 /* NA */ NULL,
193 /* NA */ NULL,
194 /* NA */ NULL,
195 /* NA */ NULL,
196 /* NA */ NULL,
197 /* NA */ NULL,
198 /* NA */ NULL,
199 /* NA */ NULL,
200 /* NA */ NULL,
201 /* NA */ NULL,
202 /* NA */ NULL,
203 /* EILSEQ */ "Illegal byte sequence",
204 /* Too high */ NULL,