1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/* <errno.h> — errors (C99 7.5, and the whole of POSIX.1-2017's set).
*
* `errno` is a macro around the platform's per-thread location, which is what
* every modern C library makes it: reading a global would be wrong in a
* threaded program, and Rust code calling into C is threaded by default.
*
* `<errno.h>` is an ISO C header and is therefore bundled — the three names C
* itself requires are `EDOM`, `ERANGE` and `EILSEQ` — but a program that uses
* `errno` at all uses the POSIX names, so the full POSIX.1-2017 list is here
* for every platform family this crate models a C library for. The numbers are
* ABI facts and are taken from the real headers: Linux's from the kernel's
* `asm-generic/errno{,-base}.h`, which glibc and musl both use unchanged;
* Apple's from xnu's `bsd/sys/errno.h`; Windows' from the Universal CRT's own
* `<errno.h>`.
*
* `_WIN32` and `__APPLE__` here are the *target's*, predefined from the model
* cinrs was told to translate for — `CINRS_TARGET`, `#pragma cinrs target`, or
* the host with neither — so a cross build takes the branch of the machine the
* program will run on rather than the one it is built on.
*
* Every definition is `#ifndef`-guarded, and the Linux branch spells `errno`,
* `EWOULDBLOCK`, `ENOTSUP` and `EDEADLOCK` exactly the way glibc spells them —
* `(*__errno_location ())` with the space glibc writes, `EWOULDBLOCK` as
* `EAGAIN` rather than as `11`. That is not fussiness: with
* `#pragma cinrs system_include` a platform header may pull in the platform's
* own `<errno.h>` after this one, and a macro redefined with a different token
* sequence is a diagnostic where one redefined identically is not. glibc's own
* `bits/errno.h` guards its additions the same way, for the same reason.
*
* The Linux numbers are the `asm-generic` ones, which every architecture Rust
* targets on Linux uses *except* MIPS and SPARC, whose kernels renumber
* everything above 34 (`EDQUOT` is 1133 on MIPS). Rather than emit wrong
* numbers there, those two architectures get only what ISO C requires.
*/
int *;
int *;
int *;
/* The three ISO C requires, which happen to agree on every platform here. */
/* ---------------------------------------------------------------------------
* Windows / Universal CRT.
*
* Two blocks: the classic 1..42 set, which is not contiguous (there is no
* ENOTBLK 15, no 26, 35, 37 or 43..99), and the POSIX block the UCRT added at
* 100. `EDEADLK` is 36 here and `ETXTBSY` 139 — not the Linux 35 and 26, which
* is the trap in copying one branch to the other. `EDQUOT`, `EMULTIHOP` and
* `ESTALE` are the three POSIX names the UCRT has no number for, so they are
* absent rather than invented.
* ------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
* Apple / Darwin (xnu `bsd/sys/errno.h`).
*
* The 4.4BSD numbering: 1..34 as everywhere, then the socket errors at 35..59
* where Linux has its own set, then 60..88, then the POSIX/STREAMS block at
* 89..106. `EAGAIN` is 35 and `EWOULDBLOCK` is the same number, as on Linux;
* `ENOTSUP` (45) and `EOPNOTSUPP` (102) are *different* numbers, which they are
* not on Linux. Darwin's header makes `EOPNOTSUPP` an alias of `ENOTSUP` only
* under the pre-10.5 `!__DARWIN_UNIX03` ABI, which no supported target uses.
* ------------------------------------------------------------------------- */
/* ---------------------------------------------------------------------------
* MIPS on Linux: the kernel renumbers everything above 34 — `EDEADLK` is 45,
* `ENOSYS` 89, `EDQUOT` famously 1133 — so only what ISO C requires is defined
* here. Guessing a POSIX number would be worse than not having it: a program
* comparing a real `errno` against the wrong constant takes the wrong branch
* and says nothing. A program that needs them on MIPS wants the platform's own
* header, through `#pragma cinrs system_include first`.
* ------------------------------------------------------------------------- */
/* SPARC on Linux, for the same reason: its numbering above 34 is the BSD-ish
* one — `EDEADLK` 78, `ENOSYS` 90, `EILSEQ` 122 — and none of it is
* `asm-generic`'s. */
/* ---------------------------------------------------------------------------
* Linux, glibc and musl alike: the kernel's `asm-generic` numbering, which is
* what every architecture Rust targets on Linux uses but MIPS and SPARC.
*
* The three aliases are written as glibc writes them rather than as numbers, so
* that the platform's own `<errno.h>` — which a system header may pull in after
* this one — redefines them *identically*.
* ------------------------------------------------------------------------- */
/* _CINRS_ERRNO_H */