5465
|
1 // oct-errno.cc.in |
|
2 /* |
|
3 |
|
4 Copyright (C) 2005 John W. Eaton |
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
|
20 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
21 02110-1301, USA. |
|
22 |
|
23 */ |
|
24 |
|
25 #ifdef HAVE_CONFIG_H |
|
26 #include <config.h> |
|
27 #endif |
|
28 |
|
29 #include <cerrno> |
|
30 |
|
31 #include "oct-errno.h" |
|
32 #include "oct-map.h" |
|
33 #include "error.h" |
|
34 |
|
35 octave_errno *octave_errno::instance = 0; |
|
36 |
|
37 octave_errno::octave_errno (void) |
|
38 { |
|
39 struct errno_struct |
|
40 { |
|
41 const char *name; |
|
42 const int value; |
|
43 }; |
|
44 |
|
45 static errno_struct errno_codes[] = |
|
46 { |
|
47 // POSIX. |
|
48 |
|
49 #if defined (E2BIG) |
|
50 { "E2BIG", E2BIG, }, |
|
51 #endif |
|
52 #if defined (EACCES) |
|
53 { "EACCES", EACCES, }, |
|
54 #endif |
|
55 #if defined (EADDRINUSE) |
|
56 { "EADDRINUSE", EADDRINUSE, }, |
|
57 #endif |
|
58 #if defined (EADDRNOTAVAIL) |
|
59 { "EADDRNOTAVAIL", EADDRNOTAVAIL, }, |
|
60 #endif |
|
61 #if defined (EAFNOSUPPORT) |
|
62 { "EAFNOSUPPORT", EAFNOSUPPORT, }, |
|
63 #endif |
|
64 #if defined (EAGAIN) |
|
65 { "EAGAIN", EAGAIN, }, |
|
66 #endif |
|
67 #if defined (EALREADY) |
|
68 { "EALREADY", EALREADY, }, |
|
69 #endif |
|
70 #if defined (EBADF) |
|
71 { "EBADF", EBADF, }, |
|
72 #endif |
|
73 #if defined (EBUSY) |
|
74 { "EBUSY", EBUSY, }, |
|
75 #endif |
|
76 #if defined (ECHILD) |
|
77 { "ECHILD", ECHILD, }, |
|
78 #endif |
|
79 #if defined (ECONNABORTED) |
|
80 { "ECONNABORTED", ECONNABORTED, }, |
|
81 #endif |
|
82 #if defined (ECONNREFUSED) |
|
83 { "ECONNREFUSED", ECONNREFUSED, }, |
|
84 #endif |
|
85 #if defined (ECONNRESET) |
|
86 { "ECONNRESET", ECONNRESET, }, |
|
87 #endif |
|
88 #if defined (EDEADLK) |
|
89 { "EDEADLK", EDEADLK, }, |
|
90 #endif |
|
91 #if defined (EDESTADDRREQ) |
|
92 { "EDESTADDRREQ", EDESTADDRREQ, }, |
|
93 #endif |
|
94 #if defined (EDOM) |
|
95 { "EDOM", EDOM, }, |
|
96 #endif |
|
97 #if defined (EDQUOT) |
|
98 { "EDQUOT", EDQUOT, }, |
|
99 #endif |
|
100 #if defined (EEXIST) |
|
101 { "EEXIST", EEXIST, }, |
|
102 #endif |
|
103 #if defined (EFAULT) |
|
104 { "EFAULT", EFAULT, }, |
|
105 #endif |
|
106 #if defined (EFBIG) |
|
107 { "EFBIG", EFBIG, }, |
|
108 #endif |
|
109 #if defined (EHOSTDOWN) |
|
110 { "EHOSTDOWN", EHOSTDOWN, }, |
|
111 #endif |
|
112 #if defined (EHOSTUNREACH) |
|
113 { "EHOSTUNREACH", EHOSTUNREACH, }, |
|
114 #endif |
|
115 #if defined (EINPROGRESS) |
|
116 { "EINPROGRESS", EINPROGRESS, }, |
|
117 #endif |
|
118 #if defined (EINTR) |
|
119 { "EINTR", EINTR, }, |
|
120 #endif |
|
121 #if defined (EINVAL) |
|
122 { "EINVAL", EINVAL, }, |
|
123 #endif |
|
124 #if defined (EIO) |
|
125 { "EIO", EIO, }, |
|
126 #endif |
|
127 #if defined (EISCONN) |
|
128 { "EISCONN", EISCONN, }, |
|
129 #endif |
|
130 #if defined (EISDIR) |
|
131 { "EISDIR", EISDIR, }, |
|
132 #endif |
|
133 #if defined (ELOOP) |
|
134 { "ELOOP", ELOOP, }, |
|
135 #endif |
|
136 #if defined (EMFILE) |
|
137 { "EMFILE", EMFILE, }, |
|
138 #endif |
|
139 #if defined (EMLINK) |
|
140 { "EMLINK", EMLINK, }, |
|
141 #endif |
|
142 #if defined (EMSGSIZE) |
|
143 { "EMSGSIZE", EMSGSIZE, }, |
|
144 #endif |
|
145 #if defined (ENAMETOOLONG) |
|
146 { "ENAMETOOLONG", ENAMETOOLONG, }, |
|
147 #endif |
|
148 #if defined (ENETDOWN) |
|
149 { "ENETDOWN", ENETDOWN, }, |
|
150 #endif |
|
151 #if defined (ENETRESET) |
|
152 { "ENETRESET", ENETRESET, }, |
|
153 #endif |
|
154 #if defined (ENETUNREACH) |
|
155 { "ENETUNREACH", ENETUNREACH, }, |
|
156 #endif |
|
157 #if defined (ENFILE) |
|
158 { "ENFILE", ENFILE, }, |
|
159 #endif |
|
160 #if defined (ENOBUFS) |
|
161 { "ENOBUFS", ENOBUFS, }, |
|
162 #endif |
|
163 #if defined (ENODEV) |
|
164 { "ENODEV", ENODEV, }, |
|
165 #endif |
|
166 #if defined (ENOENT) |
|
167 { "ENOENT", ENOENT, }, |
|
168 #endif |
|
169 #if defined (ENOEXEC) |
|
170 { "ENOEXEC", ENOEXEC, }, |
|
171 #endif |
|
172 #if defined (ENOLCK) |
|
173 { "ENOLCK", ENOLCK, }, |
|
174 #endif |
|
175 #if defined (ENOMEM) |
|
176 { "ENOMEM", ENOMEM, }, |
|
177 #endif |
|
178 #if defined (ENOPROTOOPT) |
|
179 { "ENOPROTOOPT", ENOPROTOOPT, }, |
|
180 #endif |
|
181 #if defined (ENOSPC) |
|
182 { "ENOSPC", ENOSPC, }, |
|
183 #endif |
|
184 #if defined (ENOSYS) |
|
185 { "ENOSYS", ENOSYS, }, |
|
186 #endif |
|
187 #if defined (ENOTBLK) |
|
188 { "ENOTBLK", ENOTBLK, }, |
|
189 #endif |
|
190 #if defined (ENOTCONN) |
|
191 { "ENOTCONN", ENOTCONN, }, |
|
192 #endif |
|
193 #if defined (ENOTDIR) |
|
194 { "ENOTDIR", ENOTDIR, }, |
|
195 #endif |
|
196 #if defined (ENOTEMPTY) |
|
197 { "ENOTEMPTY", ENOTEMPTY, }, |
|
198 #endif |
|
199 #if defined (ENOTSOCK) |
|
200 { "ENOTSOCK", ENOTSOCK, }, |
|
201 #endif |
|
202 #if defined (ENOTTY) |
|
203 { "ENOTTY", ENOTTY, }, |
|
204 #endif |
|
205 #if defined (ENXIO) |
|
206 { "ENXIO", ENXIO, }, |
|
207 #endif |
|
208 #if defined (EOPNOTSUPP) |
|
209 { "EOPNOTSUPP", EOPNOTSUPP, }, |
|
210 #endif |
|
211 #if defined (EPERM) |
|
212 { "EPERM", EPERM, }, |
|
213 #endif |
|
214 #if defined (EPFNOSUPPORT) |
|
215 { "EPFNOSUPPORT", EPFNOSUPPORT, }, |
|
216 #endif |
|
217 #if defined (EPIPE) |
|
218 { "EPIPE", EPIPE, }, |
|
219 #endif |
|
220 #if defined (EPROTONOSUPPORT) |
|
221 { "EPROTONOSUPPORT", EPROTONOSUPPORT, }, |
|
222 #endif |
|
223 #if defined (EPROTOTYPE) |
|
224 { "EPROTOTYPE", EPROTOTYPE, }, |
|
225 #endif |
|
226 #if defined (ERANGE) |
|
227 { "ERANGE", ERANGE, }, |
|
228 #endif |
|
229 #if defined (EREMOTE) |
|
230 { "EREMOTE", EREMOTE, }, |
|
231 #endif |
|
232 #if defined (ERESTART) |
|
233 { "ERESTART", ERESTART, }, |
|
234 #endif |
|
235 #if defined (EROFS) |
|
236 { "EROFS", EROFS, }, |
|
237 #endif |
|
238 #if defined (ESHUTDOWN) |
|
239 { "ESHUTDOWN", ESHUTDOWN, }, |
|
240 #endif |
|
241 #if defined (ESOCKTNOSUPPORT) |
|
242 { "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT, }, |
|
243 #endif |
|
244 #if defined (ESPIPE) |
|
245 { "ESPIPE", ESPIPE, }, |
|
246 #endif |
|
247 #if defined (ESRCH) |
|
248 { "ESRCH", ESRCH, }, |
|
249 #endif |
|
250 #if defined (ESTALE) |
|
251 { "ESTALE", ESTALE, }, |
|
252 #endif |
|
253 #if defined (ETIMEDOUT) |
|
254 { "ETIMEDOUT", ETIMEDOUT, }, |
|
255 #endif |
|
256 #if defined (ETOOMANYREFS) |
|
257 { "ETOOMANYREFS", ETOOMANYREFS, }, |
|
258 #endif |
|
259 #if defined (ETXTBSY) |
|
260 { "ETXTBSY", ETXTBSY, }, |
|
261 #endif |
|
262 #if defined (EUSERS) |
|
263 { "EUSERS", EUSERS, }, |
|
264 #endif |
|
265 #if defined (EWOULDBLOCK) |
|
266 { "EWOULDBLOCK", EWOULDBLOCK, }, |
|
267 #endif |
|
268 #if defined (EXDEV) |
|
269 { "EXDEV", EXDEV, }, |
|
270 #endif |
|
271 |
|
272 // Others (duplicates are OK). |
|
273 |
5494
|
274 @SYSDEP_ERRNO_LIST@ |
5465
|
275 |
|
276 { 0, 0, }, |
|
277 }; |
|
278 |
|
279 // Stuff them all in a map for fast access. |
|
280 |
|
281 errno_struct *ptr = errno_codes; |
|
282 |
|
283 while (ptr->name) |
|
284 { |
|
285 errno_tbl[ptr->name] = ptr->value; |
|
286 ptr++; |
|
287 } |
|
288 } |
|
289 |
|
290 bool |
|
291 octave_errno::instance_ok (void) |
|
292 { |
|
293 bool retval = true; |
|
294 |
|
295 if (! instance) |
|
296 instance = new octave_errno (); |
|
297 |
|
298 if (! instance) |
|
299 { |
|
300 ::error ("unable to create errno object!"); |
|
301 |
|
302 retval = false; |
|
303 } |
|
304 |
|
305 return retval; |
|
306 } |
|
307 |
|
308 int |
|
309 octave_errno::lookup (const std::string& name) |
|
310 { |
|
311 return (instance_ok ()) ? instance->do_lookup (name) : -1; |
|
312 } |
|
313 |
|
314 Octave_map |
|
315 octave_errno::list (void) |
|
316 { |
|
317 return (instance_ok ()) ? instance->do_list () : Octave_map (); |
|
318 } |
|
319 |
|
320 int |
|
321 octave_errno::do_lookup (const std::string& name) |
|
322 { |
|
323 return (errno_tbl.find (name) != errno_tbl.end ()) ? errno_tbl[name] : -1; |
|
324 } |
|
325 |
|
326 Octave_map |
|
327 octave_errno::do_list (void) |
|
328 { |
|
329 Octave_map retval; |
|
330 |
|
331 for (std::map<std::string, int>::const_iterator p = errno_tbl.begin (); |
|
332 p != errno_tbl.end (); |
|
333 p++) |
|
334 { |
|
335 retval.assign (p->first, p->second); |
|
336 } |
|
337 |
|
338 return retval; |
|
339 } |
|
340 |
|
341 /* |
|
342 ;;; Local Variables: *** |
|
343 ;;; mode: C++ *** |
|
344 ;;; page-delimiter: "^/\\*" *** |
|
345 ;;; End: *** |
|
346 */ |