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)
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/>. */
28 #include "ChanConsts.h"
30 #if defined(HAVE_ERRNO_H)
34 #if defined(HAVE_SYS_ERRNO_H)
35 #include "sys/errno.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. */
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
));
60 /* IsErrnoSoft returns true if the value of errno is associated
61 with a soft device error. */
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
));
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
));
88 /* GetOpenResults - maps errno onto the ISO Modula-2 enumerated type,
91 extern "C" openResults
92 EXPORT(GetOpenResults
) (int e
)
96 #if defined(HAVE_ERRNO_H) || defined(HAVE_SYS_ERRNO_H)
100 return wrongPermissions
;
109 return wrongPermissions
;
112 return wrongFileType
;
121 return wrongFileType
;
124 return wrongFileType
;
136 return wrongFileType
;
139 return noRoomOnDevice
;
142 return wrongPermissions
;
153 /* GNU Modula-2 linking fodder. */
156 M2EXPORT(init
) (int, char **, char **)
161 M2EXPORT(fini
) (int, char **, char **)
170 extern "C" void __attribute__((__constructor__
))
171 M2EXPORT(ctor
) (void)
173 m2iso_M2RTS_RegisterModule ("ErrnoCategory", M2LIBNAME
,
174 M2EXPORT(init
), M2EXPORT(fini
),