c++: accepts-invalid with =delete("") [PR111840]
[official-gcc.git] / libgm2 / libm2iso / ErrnoCategory.cc
blob053c75bb11ab0a3460291fa540a17cfb61d133dd
1 /* ErrnoCatogory.cc categorizes values of errno maps onto ChanConsts.h.
3 Copyright (C) 2008-2022 Free Software Foundation, Inc.
4 Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
6 This file is part of GNU Modula-2.
8 GNU Modula-2 is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
13 GNU Modula-2 is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 Under Section 7 of GPL version 3, you are granted additional
19 permissions described in the GCC Runtime Library Exception, version
20 3.1, as published by the Free Software Foundation.
22 You should have received a copy of the GNU General Public License and
23 a copy of the GCC Runtime Library Exception along with this program;
24 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
25 <http://www.gnu.org/licenses/>. */
27 #include "config.h"
28 #include "ChanConsts.h"
30 #if defined(HAVE_ERRNO_H)
31 #include "errno.h"
32 #endif
34 #if defined(HAVE_SYS_ERRNO_H)
35 #include "sys/errno.h"
36 #endif
38 #include "m2rts.h"
40 #define EXPORT(FUNC) m2iso ## _ErrnoCategory_ ## FUNC
41 #define M2EXPORT(FUNC) m2iso ## _M2_ErrnoCategory_ ## FUNC
42 #define M2LIBNAME "m2iso"
45 /* IsErrnoHard returns true if the value of errno is associated
46 with a hard device error. */
48 extern "C" bool
49 EXPORT(IsErrnoHard) (int e)
51 #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
52 return ((e == EPERM) || (e == ENOENT) || (e == EIO) || (e == ENXIO)
53 || (e == EACCES) || (e == ENOTBLK) || (e == ENODEV) || (e == EINVAL)
54 || (e == ENFILE) || (e == EROFS) || (e == EMLINK));
55 #else
56 return false;
57 #endif
60 /* IsErrnoSoft returns true if the value of errno is associated
61 with a soft device error. */
63 extern "C" bool
64 EXPORT(IsErrnoSoft) (int e)
66 #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
67 return ((e == ESRCH) || (e == EINTR) || (e == E2BIG) || (e == ENOEXEC)
68 || (e == EBADF) || (e == ECHILD) || (e == EAGAIN) || (e == ENOMEM)
69 || (e == EFAULT) || (e == EBUSY) || (e == EEXIST) || (e == EXDEV)
70 || (e == ENOTDIR) || (e == EISDIR) || (e == EMFILE) || (e == ENOTTY)
71 || (e == ETXTBSY) || (e == EFBIG) || (e == ENOSPC) || (e == EPIPE));
72 #else
73 return false;
74 #endif
77 extern "C" bool
78 EXPORT(UnAvailable) (int e)
80 #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
81 return ((e == ENOENT) || (e == ESRCH) || (e == ENXIO) || (e == ECHILD)
82 || (e == ENOTBLK) || (e == ENODEV) || (e == ENOTDIR));
83 #else
84 return false;
85 #endif
88 /* GetOpenResults - maps errno onto the ISO Modula-2 enumerated type,
89 OpenResults. */
91 extern "C" openResults
92 EXPORT(GetOpenResults) (int e)
94 if (e == 0)
95 return opened;
96 #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
97 switch (e)
99 case EPERM:
100 return wrongPermissions;
101 break;
102 case ENOENT:
103 return noSuchFile;
104 break;
105 case ENXIO:
106 return noSuchFile;
107 break;
108 case EACCES:
109 return wrongPermissions;
110 break;
111 case ENOTBLK:
112 return wrongFileType;
113 break;
114 case EEXIST:
115 return fileExists;
116 break;
117 case ENODEV:
118 return noSuchFile;
119 break;
120 case ENOTDIR:
121 return wrongFileType;
122 break;
123 case EISDIR:
124 return wrongFileType;
125 break;
126 case EINVAL:
127 return wrongFlags;
128 break;
129 case ENFILE:
130 return tooManyOpen;
131 break;
132 case EMFILE:
133 return tooManyOpen;
134 break;
135 case ENOTTY:
136 return wrongFileType;
137 break;
138 case ENOSPC:
139 return noRoomOnDevice;
140 break;
141 case EROFS:
142 return wrongPermissions;
143 break;
145 default:
146 return otherProblem;
148 #else
149 return otherProblem;
150 #endif
153 /* GNU Modula-2 linking fodder. */
155 extern "C" void
156 M2EXPORT(init) (int, char **, char **)
160 extern "C" void
161 M2EXPORT(fini) (int, char **, char **)
165 extern "C" void
166 M2EXPORT(dep) (void)
170 extern "C" void __attribute__((__constructor__))
171 M2EXPORT(ctor) (void)
173 m2iso_M2RTS_RegisterModule ("ErrnoCategory", M2LIBNAME,
174 M2EXPORT(init), M2EXPORT(fini),
175 M2EXPORT(dep));