GNU Octave  9.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-errno.cc
Go to the documentation of this file.
1 // %NO_EDIT_WARNING%
2 
3 ////////////////////////////////////////////////////////////////////////
4 //
5 // Copyright (C) 2005-2024 The Octave Project Developers
6 //
7 // See the file COPYRIGHT.md in the top-level directory of this
8 // distribution or <https://octave.org/copyright/>.
9 //
10 // This file is part of Octave.
11 //
12 // Octave is free software: you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by
14 // the Free Software Foundation, either version 3 of the License, or
15 // (at your option) any later version.
16 //
17 // Octave is distributed in the hope that it will be useful, but
18 // WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with Octave; see the file COPYING. If not, see
24 // <https://www.gnu.org/licenses/>.
25 //
26 ////////////////////////////////////////////////////////////////////////
27 
28 #if defined (HAVE_CONFIG_H)
29 # include "config.h"
30 #endif
31 
32 #include <cerrno>
33 
34 #include "singleton-cleanup.h"
35 
36 #include "oct-errno.h"
37 #include "oct-map.h"
38 #include "error.h"
39 
40 octave_errno *octave_errno::s_instance = nullptr;
41 
43 {
44  struct errno_struct
45  {
46  const char *name;
47  int value;
48  };
49 
50  static errno_struct errno_codes[] =
51  {
52  // POSIX.
53 
54 #if defined (E2BIG)
55  { "E2BIG", E2BIG },
56 #endif
57 #if defined (EACCES)
58  { "EACCES", EACCES },
59 #endif
60 #if defined (EADDRINUSE)
61  { "EADDRINUSE", EADDRINUSE },
62 #endif
63 #if defined (EADDRNOTAVAIL)
64  { "EADDRNOTAVAIL", EADDRNOTAVAIL },
65 #endif
66 #if defined (EAFNOSUPPORT)
67  { "EAFNOSUPPORT", EAFNOSUPPORT },
68 #endif
69 #if defined (EAGAIN)
70  { "EAGAIN", EAGAIN },
71 #endif
72 #if defined (EALREADY)
73  { "EALREADY", EALREADY },
74 #endif
75 #if defined (EBADF)
76  { "EBADF", EBADF },
77 #endif
78 #if defined (EBUSY)
79  { "EBUSY", EBUSY },
80 #endif
81 #if defined (ECHILD)
82  { "ECHILD", ECHILD },
83 #endif
84 #if defined (ECONNABORTED)
85  { "ECONNABORTED", ECONNABORTED },
86 #endif
87 #if defined (ECONNREFUSED)
88  { "ECONNREFUSED", ECONNREFUSED },
89 #endif
90 #if defined (ECONNRESET)
91  { "ECONNRESET", ECONNRESET },
92 #endif
93 #if defined (EDEADLK)
94  { "EDEADLK", EDEADLK },
95 #endif
96 #if defined (EDESTADDRREQ)
97  { "EDESTADDRREQ", EDESTADDRREQ },
98 #endif
99 #if defined (EDOM)
100  { "EDOM", EDOM },
101 #endif
102 #if defined (EDQUOT)
103  { "EDQUOT", EDQUOT },
104 #endif
105 #if defined (EEXIST)
106  { "EEXIST", EEXIST },
107 #endif
108 #if defined (EFAULT)
109  { "EFAULT", EFAULT },
110 #endif
111 #if defined (EFBIG)
112  { "EFBIG", EFBIG },
113 #endif
114 #if defined (EHOSTDOWN)
115  { "EHOSTDOWN", EHOSTDOWN },
116 #endif
117 #if defined (EHOSTUNREACH)
118  { "EHOSTUNREACH", EHOSTUNREACH },
119 #endif
120 #if defined (EINPROGRESS)
121  { "EINPROGRESS", EINPROGRESS },
122 #endif
123 #if defined (EINTR)
124  { "EINTR", EINTR },
125 #endif
126 #if defined (EINVAL)
127  { "EINVAL", EINVAL },
128 #endif
129 #if defined (EIO)
130  { "EIO", EIO },
131 #endif
132 #if defined (EISCONN)
133  { "EISCONN", EISCONN },
134 #endif
135 #if defined (EISDIR)
136  { "EISDIR", EISDIR },
137 #endif
138 #if defined (ELOOP)
139  { "ELOOP", ELOOP },
140 #endif
141 #if defined (EMFILE)
142  { "EMFILE", EMFILE },
143 #endif
144 #if defined (EMLINK)
145  { "EMLINK", EMLINK },
146 #endif
147 #if defined (EMSGSIZE)
148  { "EMSGSIZE", EMSGSIZE },
149 #endif
150 #if defined (ENAMETOOLONG)
151  { "ENAMETOOLONG", ENAMETOOLONG },
152 #endif
153 #if defined (ENETDOWN)
154  { "ENETDOWN", ENETDOWN },
155 #endif
156 #if defined (ENETRESET)
157  { "ENETRESET", ENETRESET },
158 #endif
159 #if defined (ENETUNREACH)
160  { "ENETUNREACH", ENETUNREACH },
161 #endif
162 #if defined (ENFILE)
163  { "ENFILE", ENFILE },
164 #endif
165 #if defined (ENOBUFS)
166  { "ENOBUFS", ENOBUFS },
167 #endif
168 #if defined (ENODEV)
169  { "ENODEV", ENODEV },
170 #endif
171 #if defined (ENOENT)
172  { "ENOENT", ENOENT },
173 #endif
174 #if defined (ENOEXEC)
175  { "ENOEXEC", ENOEXEC },
176 #endif
177 #if defined (ENOLCK)
178  { "ENOLCK", ENOLCK },
179 #endif
180 #if defined (ENOMEM)
181  { "ENOMEM", ENOMEM },
182 #endif
183 #if defined (ENOPROTOOPT)
184  { "ENOPROTOOPT", ENOPROTOOPT },
185 #endif
186 #if defined (ENOSPC)
187  { "ENOSPC", ENOSPC },
188 #endif
189 #if defined (ENOSYS)
190  { "ENOSYS", ENOSYS },
191 #endif
192 #if defined (ENOTBLK)
193  { "ENOTBLK", ENOTBLK },
194 #endif
195 #if defined (ENOTCONN)
196  { "ENOTCONN", ENOTCONN },
197 #endif
198 #if defined (ENOTDIR)
199  { "ENOTDIR", ENOTDIR },
200 #endif
201 #if defined (ENOTEMPTY)
202  { "ENOTEMPTY", ENOTEMPTY },
203 #endif
204 #if defined (ENOTSOCK)
205  { "ENOTSOCK", ENOTSOCK },
206 #endif
207 #if defined (ENOTTY)
208  { "ENOTTY", ENOTTY },
209 #endif
210 #if defined (ENXIO)
211  { "ENXIO", ENXIO },
212 #endif
213 #if defined (EOPNOTSUPP)
214  { "EOPNOTSUPP", EOPNOTSUPP },
215 #endif
216 #if defined (EPERM)
217  { "EPERM", EPERM },
218 #endif
219 #if defined (EPFNOSUPPORT)
220  { "EPFNOSUPPORT", EPFNOSUPPORT },
221 #endif
222 #if defined (EPIPE)
223  { "EPIPE", EPIPE },
224 #endif
225 #if defined (EPROTONOSUPPORT)
226  { "EPROTONOSUPPORT", EPROTONOSUPPORT },
227 #endif
228 #if defined (EPROTOTYPE)
229  { "EPROTOTYPE", EPROTOTYPE },
230 #endif
231 #if defined (ERANGE)
232  { "ERANGE", ERANGE },
233 #endif
234 #if defined (EREMOTE)
235  { "EREMOTE", EREMOTE },
236 #endif
237 #if defined (ERESTART)
238  { "ERESTART", ERESTART },
239 #endif
240 #if defined (EROFS)
241  { "EROFS", EROFS },
242 #endif
243 #if defined (ESHUTDOWN)
244  { "ESHUTDOWN", ESHUTDOWN },
245 #endif
246 #if defined (ESOCKTNOSUPPORT)
247  { "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT },
248 #endif
249 #if defined (ESPIPE)
250  { "ESPIPE", ESPIPE },
251 #endif
252 #if defined (ESRCH)
253  { "ESRCH", ESRCH },
254 #endif
255 #if defined (ESTALE)
256  { "ESTALE", ESTALE },
257 #endif
258 #if defined (ETIMEDOUT)
259  { "ETIMEDOUT", ETIMEDOUT },
260 #endif
261 #if defined (ETOOMANYREFS)
262  { "ETOOMANYREFS", ETOOMANYREFS },
263 #endif
264 #if defined (ETXTBSY)
265  { "ETXTBSY", ETXTBSY },
266 #endif
267 #if defined (EUSERS)
268  { "EUSERS", EUSERS },
269 #endif
270 #if defined (EWOULDBLOCK)
271  { "EWOULDBLOCK", EWOULDBLOCK },
272 #endif
273 #if defined (EXDEV)
274  { "EXDEV", EXDEV },
275 #endif
276 
277  // Others (duplicates are OK).
278 
279 #if defined (E2BIG)
280  { "E2BIG", E2BIG },
281 #endif
282 #if defined (EACCES)
283  { "EACCES", EACCES },
284 #endif
285 #if defined (EADDRINUSE)
286  { "EADDRINUSE", EADDRINUSE },
287 #endif
288 #if defined (EADDRNOTAVAIL)
289  { "EADDRNOTAVAIL", EADDRNOTAVAIL },
290 #endif
291 #if defined (EADV)
292  { "EADV", EADV },
293 #endif
294 #if defined (EAFNOSUPPORT)
295  { "EAFNOSUPPORT", EAFNOSUPPORT },
296 #endif
297 #if defined (EAGAIN)
298  { "EAGAIN", EAGAIN },
299 #endif
300 #if defined (EALREADY)
301  { "EALREADY", EALREADY },
302 #endif
303 #if defined (EBADE)
304  { "EBADE", EBADE },
305 #endif
306 #if defined (EBADF)
307  { "EBADF", EBADF },
308 #endif
309 #if defined (EBADFD)
310  { "EBADFD", EBADFD },
311 #endif
312 #if defined (EBADMSG)
313  { "EBADMSG", EBADMSG },
314 #endif
315 #if defined (EBADR)
316  { "EBADR", EBADR },
317 #endif
318 #if defined (EBADRQC)
319  { "EBADRQC", EBADRQC },
320 #endif
321 #if defined (EBADSLT)
322  { "EBADSLT", EBADSLT },
323 #endif
324 #if defined (EBFONT)
325  { "EBFONT", EBFONT },
326 #endif
327 #if defined (EBUSY)
328  { "EBUSY", EBUSY },
329 #endif
330 #if defined (ECANCELED)
331  { "ECANCELED", ECANCELED },
332 #endif
333 #if defined (ECHILD)
334  { "ECHILD", ECHILD },
335 #endif
336 #if defined (ECHRNG)
337  { "ECHRNG", ECHRNG },
338 #endif
339 #if defined (ECOMM)
340  { "ECOMM", ECOMM },
341 #endif
342 #if defined (ECONNABORTED)
343  { "ECONNABORTED", ECONNABORTED },
344 #endif
345 #if defined (ECONNREFUSED)
346  { "ECONNREFUSED", ECONNREFUSED },
347 #endif
348 #if defined (ECONNRESET)
349  { "ECONNRESET", ECONNRESET },
350 #endif
351 #if defined (EDEADLK)
352  { "EDEADLK", EDEADLK },
353 #endif
354 #if defined (EDEADLOCK)
355  { "EDEADLOCK", EDEADLOCK },
356 #endif
357 #if defined (EDESTADDRREQ)
358  { "EDESTADDRREQ", EDESTADDRREQ },
359 #endif
360 #if defined (EDOM)
361  { "EDOM", EDOM },
362 #endif
363 #if defined (EDOTDOT)
364  { "EDOTDOT", EDOTDOT },
365 #endif
366 #if defined (EDQUOT)
367  { "EDQUOT", EDQUOT },
368 #endif
369 #if defined (EEXIST)
370  { "EEXIST", EEXIST },
371 #endif
372 #if defined (EFAULT)
373  { "EFAULT", EFAULT },
374 #endif
375 #if defined (EFBIG)
376  { "EFBIG", EFBIG },
377 #endif
378 #if defined (EHOSTDOWN)
379  { "EHOSTDOWN", EHOSTDOWN },
380 #endif
381 #if defined (EHOSTUNREACH)
382  { "EHOSTUNREACH", EHOSTUNREACH },
383 #endif
384 #if defined (EHWPOISON)
385  { "EHWPOISON", EHWPOISON },
386 #endif
387 #if defined (EIDRM)
388  { "EIDRM", EIDRM },
389 #endif
390 #if defined (EILSEQ)
391  { "EILSEQ", EILSEQ },
392 #endif
393 #if defined (EINPROGRESS)
394  { "EINPROGRESS", EINPROGRESS },
395 #endif
396 #if defined (EINTR)
397  { "EINTR", EINTR },
398 #endif
399 #if defined (EINVAL)
400  { "EINVAL", EINVAL },
401 #endif
402 #if defined (EIO)
403  { "EIO", EIO },
404 #endif
405 #if defined (EISCONN)
406  { "EISCONN", EISCONN },
407 #endif
408 #if defined (EISDIR)
409  { "EISDIR", EISDIR },
410 #endif
411 #if defined (EISNAM)
412  { "EISNAM", EISNAM },
413 #endif
414 #if defined (EKEYEXPIRED)
415  { "EKEYEXPIRED", EKEYEXPIRED },
416 #endif
417 #if defined (EKEYREJECTED)
418  { "EKEYREJECTED", EKEYREJECTED },
419 #endif
420 #if defined (EKEYREVOKED)
421  { "EKEYREVOKED", EKEYREVOKED },
422 #endif
423 #if defined (EL2HLT)
424  { "EL2HLT", EL2HLT },
425 #endif
426 #if defined (EL2NSYNC)
427  { "EL2NSYNC", EL2NSYNC },
428 #endif
429 #if defined (EL3HLT)
430  { "EL3HLT", EL3HLT },
431 #endif
432 #if defined (EL3RST)
433  { "EL3RST", EL3RST },
434 #endif
435 #if defined (ELIBACC)
436  { "ELIBACC", ELIBACC },
437 #endif
438 #if defined (ELIBBAD)
439  { "ELIBBAD", ELIBBAD },
440 #endif
441 #if defined (ELIBEXEC)
442  { "ELIBEXEC", ELIBEXEC },
443 #endif
444 #if defined (ELIBMAX)
445  { "ELIBMAX", ELIBMAX },
446 #endif
447 #if defined (ELIBSCN)
448  { "ELIBSCN", ELIBSCN },
449 #endif
450 #if defined (ELNRNG)
451  { "ELNRNG", ELNRNG },
452 #endif
453 #if defined (ELOOP)
454  { "ELOOP", ELOOP },
455 #endif
456 #if defined (EMEDIUMTYPE)
457  { "EMEDIUMTYPE", EMEDIUMTYPE },
458 #endif
459 #if defined (EMFILE)
460  { "EMFILE", EMFILE },
461 #endif
462 #if defined (EMLINK)
463  { "EMLINK", EMLINK },
464 #endif
465 #if defined (EMSGSIZE)
466  { "EMSGSIZE", EMSGSIZE },
467 #endif
468 #if defined (EMULTIHOP)
469  { "EMULTIHOP", EMULTIHOP },
470 #endif
471 #if defined (ENAMETOOLONG)
472  { "ENAMETOOLONG", ENAMETOOLONG },
473 #endif
474 #if defined (ENAVAIL)
475  { "ENAVAIL", ENAVAIL },
476 #endif
477 #if defined (ENETDOWN)
478  { "ENETDOWN", ENETDOWN },
479 #endif
480 #if defined (ENETRESET)
481  { "ENETRESET", ENETRESET },
482 #endif
483 #if defined (ENETUNREACH)
484  { "ENETUNREACH", ENETUNREACH },
485 #endif
486 #if defined (ENFILE)
487  { "ENFILE", ENFILE },
488 #endif
489 #if defined (ENOANO)
490  { "ENOANO", ENOANO },
491 #endif
492 #if defined (ENOBUFS)
493  { "ENOBUFS", ENOBUFS },
494 #endif
495 #if defined (ENOCSI)
496  { "ENOCSI", ENOCSI },
497 #endif
498 #if defined (ENODATA)
499  { "ENODATA", ENODATA },
500 #endif
501 #if defined (ENODEV)
502  { "ENODEV", ENODEV },
503 #endif
504 #if defined (ENOENT)
505  { "ENOENT", ENOENT },
506 #endif
507 #if defined (ENOEXEC)
508  { "ENOEXEC", ENOEXEC },
509 #endif
510 #if defined (ENOKEY)
511  { "ENOKEY", ENOKEY },
512 #endif
513 #if defined (ENOLCK)
514  { "ENOLCK", ENOLCK },
515 #endif
516 #if defined (ENOLINK)
517  { "ENOLINK", ENOLINK },
518 #endif
519 #if defined (ENOMEDIUM)
520  { "ENOMEDIUM", ENOMEDIUM },
521 #endif
522 #if defined (ENOMEM)
523  { "ENOMEM", ENOMEM },
524 #endif
525 #if defined (ENOMSG)
526  { "ENOMSG", ENOMSG },
527 #endif
528 #if defined (ENONET)
529  { "ENONET", ENONET },
530 #endif
531 #if defined (ENOPKG)
532  { "ENOPKG", ENOPKG },
533 #endif
534 #if defined (ENOPROTOOPT)
535  { "ENOPROTOOPT", ENOPROTOOPT },
536 #endif
537 #if defined (ENOSPC)
538  { "ENOSPC", ENOSPC },
539 #endif
540 #if defined (ENOSR)
541  { "ENOSR", ENOSR },
542 #endif
543 #if defined (ENOSTR)
544  { "ENOSTR", ENOSTR },
545 #endif
546 #if defined (ENOSYS)
547  { "ENOSYS", ENOSYS },
548 #endif
549 #if defined (ENOTBLK)
550  { "ENOTBLK", ENOTBLK },
551 #endif
552 #if defined (ENOTCONN)
553  { "ENOTCONN", ENOTCONN },
554 #endif
555 #if defined (ENOTDIR)
556  { "ENOTDIR", ENOTDIR },
557 #endif
558 #if defined (ENOTEMPTY)
559  { "ENOTEMPTY", ENOTEMPTY },
560 #endif
561 #if defined (ENOTNAM)
562  { "ENOTNAM", ENOTNAM },
563 #endif
564 #if defined (ENOTRECOVERABLE)
565  { "ENOTRECOVERABLE", ENOTRECOVERABLE },
566 #endif
567 #if defined (ENOTSOCK)
568  { "ENOTSOCK", ENOTSOCK },
569 #endif
570 #if defined (ENOTSUP)
571  { "ENOTSUP", ENOTSUP },
572 #endif
573 #if defined (ENOTTY)
574  { "ENOTTY", ENOTTY },
575 #endif
576 #if defined (ENOTUNIQ)
577  { "ENOTUNIQ", ENOTUNIQ },
578 #endif
579 #if defined (ENXIO)
580  { "ENXIO", ENXIO },
581 #endif
582 #if defined (EOPNOTSUPP)
583  { "EOPNOTSUPP", EOPNOTSUPP },
584 #endif
585 #if defined (EOVERFLOW)
586  { "EOVERFLOW", EOVERFLOW },
587 #endif
588 #if defined (EOWNERDEAD)
589  { "EOWNERDEAD", EOWNERDEAD },
590 #endif
591 #if defined (EPERM)
592  { "EPERM", EPERM },
593 #endif
594 #if defined (EPFNOSUPPORT)
595  { "EPFNOSUPPORT", EPFNOSUPPORT },
596 #endif
597 #if defined (EPIPE)
598  { "EPIPE", EPIPE },
599 #endif
600 #if defined (EPROTO)
601  { "EPROTO", EPROTO },
602 #endif
603 #if defined (EPROTONOSUPPORT)
604  { "EPROTONOSUPPORT", EPROTONOSUPPORT },
605 #endif
606 #if defined (EPROTOTYPE)
607  { "EPROTOTYPE", EPROTOTYPE },
608 #endif
609 #if defined (ERANGE)
610  { "ERANGE", ERANGE },
611 #endif
612 #if defined (EREMCHG)
613  { "EREMCHG", EREMCHG },
614 #endif
615 #if defined (EREMOTE)
616  { "EREMOTE", EREMOTE },
617 #endif
618 #if defined (EREMOTEIO)
619  { "EREMOTEIO", EREMOTEIO },
620 #endif
621 #if defined (ERESTART)
622  { "ERESTART", ERESTART },
623 #endif
624 #if defined (ERFKILL)
625  { "ERFKILL", ERFKILL },
626 #endif
627 #if defined (EROFS)
628  { "EROFS", EROFS },
629 #endif
630 #if defined (ESHUTDOWN)
631  { "ESHUTDOWN", ESHUTDOWN },
632 #endif
633 #if defined (ESOCKTNOSUPPORT)
634  { "ESOCKTNOSUPPORT", ESOCKTNOSUPPORT },
635 #endif
636 #if defined (ESPIPE)
637  { "ESPIPE", ESPIPE },
638 #endif
639 #if defined (ESRCH)
640  { "ESRCH", ESRCH },
641 #endif
642 #if defined (ESRMNT)
643  { "ESRMNT", ESRMNT },
644 #endif
645 #if defined (ESTALE)
646  { "ESTALE", ESTALE },
647 #endif
648 #if defined (ESTRPIPE)
649  { "ESTRPIPE", ESTRPIPE },
650 #endif
651 #if defined (ETIME)
652  { "ETIME", ETIME },
653 #endif
654 #if defined (ETIMEDOUT)
655  { "ETIMEDOUT", ETIMEDOUT },
656 #endif
657 #if defined (ETOOMANYREFS)
658  { "ETOOMANYREFS", ETOOMANYREFS },
659 #endif
660 #if defined (ETXTBSY)
661  { "ETXTBSY", ETXTBSY },
662 #endif
663 #if defined (EUCLEAN)
664  { "EUCLEAN", EUCLEAN },
665 #endif
666 #if defined (EUNATCH)
667  { "EUNATCH", EUNATCH },
668 #endif
669 #if defined (EUSERS)
670  { "EUSERS", EUSERS },
671 #endif
672 #if defined (EWOULDBLOCK)
673  { "EWOULDBLOCK", EWOULDBLOCK },
674 #endif
675 #if defined (EXDEV)
676  { "EXDEV", EXDEV },
677 #endif
678 #if defined (EXFULL)
679  { "EXFULL", EXFULL },
680 #endif
681 
682 
683  { nullptr, 0 },
684  };
685 
686  // Stuff them all in a map for fast access.
687 
688  errno_struct *ptr = errno_codes;
689 
690  while (ptr->name)
691  {
692  m_errno_tbl[ptr->name] = ptr->value;
693  ptr++;
694  }
695 }
696 
697 bool
699 {
700  bool retval = true;
701 
702  if (! s_instance)
703  {
704  s_instance = new octave_errno ();
706  }
707 
708  return retval;
709 }
710 
711 int
712 octave_errno::lookup (const std::string& name)
713 {
714  return (instance_ok ()) ? s_instance->do_lookup (name) : -1;
715 }
716 
719 {
720  return (instance_ok ()) ? s_instance->do_list () : octave_scalar_map ();
721 }
722 
723 int
724 octave_errno::do_lookup (const std::string& name)
725 {
726  return (m_errno_tbl.find (name) != m_errno_tbl.end ()) ? m_errno_tbl[name]
727  : -1;
728 }
729 
731 octave_errno::do_list ()
732 {
733  octave_scalar_map retval;
734 
735  for (const auto& p : m_errno_tbl)
736  {
737  retval.assign (p.first, p.second);
738  }
739 
740  return retval;
741 }
static octave_scalar_map list()
Definition: oct-errno.cc:718
static void cleanup_instance()
Definition: oct-errno.h:52
static int lookup(const std::string &name)
Definition: oct-errno.cc:712
static bool instance_ok()
Definition: oct-errno.cc:698
void assign(const std::string &k, const octave_value &val)
Definition: oct-map.h:230
static void add(fptr f)