P99
p99_errno.h
Go to the documentation of this file.
1 /* This may look like nonsense, but it really is -*- mode: C; coding: utf-8 -*- */
2 /* */
3 /* Except for parts copied from previous work and as explicitly stated below, */
4 /* the author and copyright holder for this work is */
5 /* (C) copyright 2012-2013 Jens Gustedt, INRIA, France */
6 /* */
7 /* This file is free software; it is part of the P99 project. */
8 /* */
9 /* Licensed under the Apache License, Version 2.0 (the "License"); */
10 /* you may not use this file except in compliance with the License. */
11 /* You may obtain a copy of the License at */
12 /* */
13 /* http://www.apache.org/licenses/LICENSE-2.0 */
14 /* */
15 /* Unless required by applicable law or agreed to in writing, software */
16 /* distributed under the License is distributed on an "AS IS" BASIS, */
17 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
18 /* See the License for the specific language governing permissions and */
19 /* limitations under the License. */
20 /* */
21 #ifndef P99_ERRNO_H_
22 # define P99_ERRNO_H_
23 
24 #include "p99_for.h"
25 
26 #define P00_IF_XEQ_(A, B) P99_IF_EQ(A, B)
27 #define P00_IF_XEQ(A, B) P00_IF_XEQ(A, B)
28 
29 
30 /* A long list of error numbers. C11 only has EDOM, EILSEQ, ERANGE but
31  usually systems declare their own values:
32 
33  Additional macro definitions, beginning with E and a digit or E and
34  an uppercase letter,203) may also be specified by the
35  implementation.
36 
37  For the moment this list is from what Linux has to offer. This
38  includes the macros that are defined by POSIX.
39  */
40 #define P00_ERRNO_LIST \
41  2BIG, \
42  ACCES, \
43  ADDRINUSE, \
44  ADDRNOTAVAIL, \
45  AFNOSUPPORT, \
46  /* POSIX allows these two to be equal */ \
47  P99_IF_EQ(EAGAIN, EWOULDBLOCK)(AGAIN,)(AGAIN, WOULDBLOCK,) \
48  ALREADY, \
49  BADE, \
50  BADF, \
51  BADFD, \
52  BADMSG, \
53  BADR, \
54  BADRQC, \
55  BADSLT, \
56  BUSY, \
57  CANCELED, \
58  CHILD, \
59  CHRNG, \
60  COMM, \
61  CONNABORTED, \
62  CONNREFUSED, \
63  CONNRESET, \
64  /* POSIX has only EDEADLK, Linux also has EDEADLOCK */ \
65  P99_IF_EQ(EDEADLK, EDEADLOCK)(DEADLK,)(DEADLK, DEADLOCK,) \
66  DESTADDRREQ, \
67  DOM, \
68  DQUOT, \
69  EXIST, \
70  FAULT, \
71  FBIG, \
72  HOSTDOWN, \
73  HOSTUNREACH, \
74  IDRM, \
75  ILSEQ, \
76  INPROGRESS, \
77  INTR, \
78  INVAL, \
79  IO, \
80  ISCONN, \
81  ISDIR, \
82  ISNAM, \
83  KEYEXPIRED, \
84  KEYREJECTED, \
85  KEYREVOKED, \
86  L2HLT, \
87  L2NSYNC, \
88  L3HLT, \
89  L3RST, \
90  LIBACC, \
91  LIBBAD, \
92  LIBEXEC, \
93  LIBMAX, \
94  LIBSCN, \
95  LOOP, \
96  MEDIUMTYPE, \
97  MFILE, \
98  MLINK, \
99  MSGSIZE, \
100  MULTIHOP, \
101  NAMETOOLONG, \
102  NETDOWN, \
103  NETRESET, \
104  NETUNREACH, \
105  NFILE, \
106  NOBUFS, \
107  NODATA, \
108  NODEV, \
109  NOENT, \
110  NOEXEC, \
111  NOKEY, \
112  NOLCK, \
113  NOLINK, \
114  NOMEDIUM, \
115  NOMEM, \
116  NOMSG, \
117  NONET, \
118  NOPKG, \
119  NOPROTOOPT, \
120  NOSPC, \
121  NOSR, \
122  NOSTR, \
123  NOSYS, \
124  NOTBLK, \
125  NOTCONN, \
126  NOTDIR, \
127  NOTEMPTY, \
128  NOTSOCK, \
129  NOTTY, \
130  NOTUNIQ, \
131  NXIO, \
132  /* should be distinct for POSIX, but are equal on Linux */ \
133  P99_IF_EQ(ENOTSUP, EOPNOTSUPP)(NOTSUP,)(NOTSUP, OPNOTSUPP,) \
134  /* is defined by SVID as such: OVERFLOW, */ \
135  PERM, \
136  PFNOSUPPORT, \
137  PIPE, \
138  PROTO, \
139  PROTONOSUPPORT, \
140  PROTOTYPE, \
141  RANGE, \
142  REMCHG, \
143  REMOTE, \
144  REMOTEIO, \
145  RESTART, \
146  ROFS, \
147  SHUTDOWN, \
148  SOCKTNOSUPPORT, \
149  SPIPE, \
150  SRCH, \
151  STALE, \
152  STRPIPE, \
153  TIME, \
154  TIMEDOUT, \
155  TXTBSY, \
156  UCLEAN, \
157  UNATCH, \
158  USERS, \
159  XDEV, \
160  XFULL, \
161  XXX
162 
163 #define P00_ERRNO_ELEM_(ERR, STR) P99_IF_GT(ERR, 0)([ERR] = 0,)()
164 #define P00_ERRNO_ELEM(ERR) P00_ERRNO_ELEM_(E ## ERR, "E" #ERR)
165 
166 #define P00_ERRNO_ENUM_(ERR, NAME) P99_IF_GT(ERR, 0)(NAME)(ERR)
167 #define P00_ERRNO_ENUM(ERR) P00_ERRNO_ENUM_(E ## ERR, p00_E ## ERR)
168 
169 enum {
173  p00_errno_max = sizeof((char[]) { P99_SER(P00_ERRNO_ELEM, P00_ERRNO_LIST) P00_ERRNO_ELEM(OVERFLOW) }),
174  /* Add all other codes as enumeration constants */
175  P99_SEQ(P00_ERRNO_ENUM, P00_ERRNO_LIST), P00_ERRNO_ENUM(OVERFLOW),
180 };
181 
182 #define P00_ERRNO_CASE_(ERR, STR) case ERR: return STR
183 #define P00_ERRNO_CASE(ERR) P00_ERRNO_CASE_(E ## ERR, "E" #ERR)
184 
198 char const* p99_errno_getname(errno_t p00_err) {
199  switch (p00_err) {
200  P99_SEP(P00_ERRNO_CASE, P00_ERRNO_LIST);
201  P00_ERRNO_CASE(OVERFLOW);
202  default: return 0;
203  }
204 }
205 
206 #endif
p99_for.h
A preprocessor for loop implementation and some derived list handling macros.
p99_errno_max
@ p99_errno_max
The maximum error code that we found or defined on this system.
Definition: p99_errno.h:179
P99_SER
#define P99_SER(MACRO,...)
Apply the macro MACRO to the rest of the argument list.
Definition: p99_for.h:264
P99_SEP
#define P99_SEP(MACRO,...)
Apply the macro MACRO to the rest of the argument list.
Definition: p99_for.h:297
p99_errno_getname
char const * p99_errno_getname(errno_t p00_err)
Return the name of an error condition.
Definition: p99_errno.h:198
p99_inline
#define p99_inline
Try to force a function always to be inlined.
Definition: p99_compiler.h:496
P99_SEQ
#define P99_SEQ(MACRO,...)
Apply the macro MACRO to the rest of the argument list.
Definition: p99_for.h:250
P99_CONST_FUNCTION
#define P99_CONST_FUNCTION
On architectures that support this, assert that a function is "const", i.e only depends on parameters...
Definition: p99_compiler.h:622
errno_t
int errno_t
Definition: p99_type.h:38