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