make armeb specific header (set AROS_BIG_ENDIAN to one)
[AROS.git] / compiler / stdc / strerror.c
blob66152a41759416e1af613cd3c4f87484e0bb0e1b
1 /*
2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function strerror().
6 */
8 #include <proto/exec.h>
10 #define __NOBLIBBASE__
12 #include <proto/dos.h>
14 #include <clib/macros.h>
15 #include <stdlib.h>
16 #include <errno.h>
18 #include "__stdc_intbase.h"
20 static const char * _errstrings[];
22 /*****************************************************************************
24 NAME
25 #include <string.h>
27 char * strerror (
29 SYNOPSIS
30 int n)
32 FUNCTION
33 Returns a readable string for an error number in errno.
35 INPUTS
36 n - The contents of errno or a #define from errno.h
38 RESULT
39 A string describing the error.
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 __stdc_strerror()
50 INTERNALS
52 ******************************************************************************/
54 /*****************************************************************************
56 NAME */
57 #include <string.h>
59 char * __stdc_strerror (
61 /* SYNOPSIS */
62 int n)
64 /* FUNCTION
65 Returns a readable string for an error number in errno.
67 INPUTS
68 n - The contents of errno or a #define from errno.h
70 RESULT
71 A string describing the error.
73 NOTES
74 This functions only handles the error codes needed by C99 and the ones
75 used in stdc.library. This function is aliased as strerror() in
76 libstdc.a
77 Other libraries may override this function by providing this function
78 also in their libxxx.a file. They can internally call __stdc_strerror
79 to get the strings for the errors handled by this function.
81 EXAMPLE
83 BUGS
85 SEE ALSO
86 strerror()
88 INTERNALS
90 ******************************************************************************/
92 if (n > MAX_ERRNO)
94 struct StdCIntBase *StdCBase =
95 (struct StdCIntBase *)__aros_getbase_StdCBase();
96 #define DOSBase StdCBase->StdCDOSBase
98 if (StdCBase->fault_buf == NULL)
99 /* This is not freed anywhere, will be cleaned when
100 libbase is expunged
102 StdCBase->fault_buf = malloc(100);
104 Fault(n - MAX_ERRNO, NULL, StdCBase->fault_buf, 100);
105 #undef DOSBase
106 return StdCBase->fault_buf;
108 else
110 char *s;
112 s = (char *)_errstrings[MIN(n, __STDC_ELAST+1)];
114 if (s == NULL)
115 s = (char *)"Errno out of range";
117 return s;
119 } /* strerror */
122 static const char * _errstrings[__STDC_ELAST+2] =
124 /* 0 */ "No error",
125 /* NA */ NULL,
126 /* ENOENT */ "No such file or directory",
127 /* NA */ NULL,
128 /* EINTR */ "Interrupted system call",
129 /* NA */ NULL,
130 /* NA */ NULL,
131 /* NA */ NULL,
132 /* ENOEXEC */ "Exec format error",
133 /* NA */ NULL,
134 /* NA */ NULL,
135 /* NA */ NULL,
136 /* ENOMEM */ "Out of memory",
137 /* EACCES */ "Permission denied",
138 /* NA */ NULL,
139 /* NA */ NULL,
140 /* EBUSY */ "Device or resource busy",
141 /* EEXIST */ "File exists",
142 /* EXDEV */ "Cross-device link",
143 /* NA */ NULL,
144 /* ENOTDIR */ "Not a directory",
145 /* NA */ NULL,
146 /* EINVAL */ "Invalid argument",
147 /* NA */ NULL,
148 /* NA */ NULL,
149 /* NA */ NULL,
150 /* NA */ NULL,
151 /* NA */ NULL,
152 /* NA */ NULL,
153 /* NA */ NULL,
154 /* NA */ NULL,
155 /* NA */ NULL,
156 /* NA */ NULL,
157 /* EDOM */ "Numerical argument out of domain",
158 /* ERANGE */ "Math result not representable",
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 /* NA */ NULL,
174 /* NA */ NULL,
175 /* NA */ NULL,
176 /* NA */ NULL,
177 /* NA */ NULL,
178 /* NA */ NULL,
179 /* ENOBUFS */ "No buffer space available",
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 /* NA */ NULL,
204 /* NA */ NULL,
205 /* NA */ NULL,
206 /* NA */ NULL,
207 /* NA */ NULL,
208 /* NA */ NULL,
209 /* EILSEQ */ "Illegal byte sequence",
210 /* Too high */ NULL,
213 static int __stdc_dosinit(struct StdCIntBase *StdCBase)
215 StdCBase->StdCDOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 0);
217 return 1;
220 ADD2OPENLIB(__stdc_dosinit, 0);