1#![cfg_attr(all(not(doc), not(feature = "std")), no_std)]
4#![cfg_attr(doc, feature(doc_cfg, doc_auto_cfg, doc_cfg_hide))]
5#![cfg_attr(doc, doc(cfg_hide(doc)))]
6pub mod linux;
7pub(crate) mod macros;
8
9#[cfg(any(
10 all(any(target_os = "linux", target_os = "android"), target_arch = "x86"),
11 feature = "x86",
12 doc
13))]
14pub mod x86 {
15 pub use super::linux::x86::Errno;
17 #[cfg(any(doc, feature = "iter"))]
18 pub use super::linux::x86::ErrnoIter;
19}
20#[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "x86"))]
21pub use x86::Errno;
22#[cfg(all(
23 any(target_os = "linux", target_os = "android"),
24 any(feature = "iter", doc),
25 target_arch = "x86"
26))]
27pub use x86::ErrnoIter;
28
29#[cfg(any(
30 all(
31 any(target_os = "linux", target_os = "android"),
32 target_arch = "x86_64"
33 ),
34 feature = "x86_64",
35 doc
36))]
37pub mod x86_64 {
38 pub use super::linux::x86::Errno;
40 #[cfg(any(doc, feature = "iter"))]
41 pub use super::linux::x86::ErrnoIter;
42}
43#[cfg(all(
44 any(target_os = "linux", target_os = "android"),
45 target_arch = "x86_64"
46))]
47pub use x86_64::Errno;
48#[cfg(all(
49 any(target_os = "linux", target_os = "android"),
50 any(feature = "iter", doc),
51 target_arch = "x86_64"
52))]
53pub use x86_64::ErrnoIter;
54
55#[cfg(any(
56 all(any(target_os = "linux", target_os = "android"), target_arch = "arm"),
57 feature = "arm",
58 doc
59))]
60pub mod arm {
61 pub use super::linux::arm::Errno;
63 #[cfg(any(doc, feature = "iter"))]
64 pub use super::linux::arm::ErrnoIter;
65}
66#[cfg(all(any(target_os = "linux", target_os = "android"), target_arch = "arm"))]
67pub use arm::Errno;
68#[cfg(all(
69 any(target_os = "linux", target_os = "android"),
70 any(feature = "iter", doc),
71 target_arch = "arm"
72))]
73pub use arm::ErrnoIter;
74
75#[cfg(any(
76 all(
77 any(target_os = "linux", target_os = "android"),
78 target_arch = "aarch64"
79 ),
80 feature = "aarch64",
81 doc
82))]
83pub mod aarch64 {
84 pub use super::linux::arm64::Errno;
86 #[cfg(any(doc, feature = "iter"))]
87 pub use super::linux::arm64::ErrnoIter;
88}
89#[cfg(all(
90 any(target_os = "linux", target_os = "android"),
91 target_arch = "aarch64"
92))]
93pub use aarch64::Errno;
94#[cfg(all(
95 any(target_os = "linux", target_os = "android"),
96 any(feature = "iter", doc),
97 target_arch = "aarch64"
98))]
99pub use aarch64::ErrnoIter;
100
101#[cfg(any(
102 all(target_os = "linux", target_arch = "hexagon"),
103 feature = "hexagon",
104 doc
105))]
106pub mod hexagon {
107 pub use super::linux::hexagon::Errno;
109 #[cfg(any(doc, feature = "iter"))]
110 pub use super::linux::hexagon::ErrnoIter;
111}
112#[cfg(all(target_os = "linux", target_arch = "hexagon"))]
113pub use hexagon::Errno;
114#[cfg(all(
115 any(feature = "iter", doc),
116 target_os = "linux",
117 target_arch = "hexagon"
118))]
119pub use hexagon::ErrnoIter;
120
121#[cfg(any(
122 all(target_os = "linux", target_arch = "s390x"),
123 feature = "s390x",
124 doc
125))]
126pub mod s390x {
127 pub use super::linux::s390::Errno;
129 #[cfg(any(doc, feature = "iter"))]
130 pub use super::linux::s390::ErrnoIter;
131}
132#[cfg(all(target_os = "linux", target_arch = "s390x"))]
133pub use s390x::Errno;
134#[cfg(all(any(feature = "iter", doc), target_os = "linux", target_arch = "s390x"))]
135pub use s390x::ErrnoIter;
136
137#[cfg(any(
138 all(target_os = "linux", target_arch = "powerpc"),
139 feature = "powerpc",
140 doc
141))]
142pub mod powerpc {
143 pub use super::linux::powerpc::Errno;
145 #[cfg(any(doc, feature = "iter"))]
146 pub use super::linux::powerpc::ErrnoIter;
147}
148#[cfg(all(target_os = "linux", target_arch = "powerpc"))]
149pub use powerpc::Errno;
150#[cfg(all(
151 any(feature = "iter", doc),
152 target_os = "linux",
153 target_arch = "powerpc"
154))]
155pub use powerpc::ErrnoIter;
156
157#[cfg(any(
158 all(target_os = "linux", target_arch = "powerpc64"),
159 feature = "powerpc64",
160 doc
161))]
162pub mod powerpc64 {
163 pub use super::linux::powerpc::Errno;
165 #[cfg(any(doc, feature = "iter"))]
166 pub use super::linux::powerpc::ErrnoIter;
167}
168#[cfg(all(target_os = "linux", target_arch = "powerpc64"))]
169pub use powerpc64::Errno;
170#[cfg(all(
171 any(feature = "iter", doc),
172 target_os = "linux",
173 target_arch = "powerpc64"
174))]
175pub use powerpc64::ErrnoIter;
176
177#[cfg(any(all(target_os = "linux", target_arch = "mips"), feature = "mips", doc))]
178pub mod mips {
179 pub use super::linux::mips::Errno;
181 #[cfg(any(doc, feature = "iter"))]
182 pub use super::linux::mips::ErrnoIter;
183}
184#[cfg(all(target_os = "linux", target_arch = "mips"))]
185pub use mips::Errno;
186#[cfg(all(any(feature = "iter", doc), target_os = "linux", target_arch = "mips"))]
187pub use mips::ErrnoIter;
188
189#[cfg(any(
190 all(target_os = "linux", target_arch = "mips64"),
191 feature = "mips64",
192 doc
193))]
194pub mod mips64 {
195 pub use super::linux::mips::Errno;
197 #[cfg(any(doc, feature = "iter"))]
198 pub use super::linux::mips::ErrnoIter;
199}
200#[cfg(all(target_os = "linux", target_arch = "mips64"))]
201pub use mips64::Errno;
202#[cfg(all(
203 any(feature = "iter", doc),
204 target_os = "linux",
205 target_arch = "mips64"
206))]
207pub use mips64::ErrnoIter;
208
209#[cfg(any(all(target_os = "linux", target_arch = "m68k"), feature = "m68k", doc))]
210pub mod m68k {
211 pub use super::linux::m68k::Errno;
213 #[cfg(any(doc, feature = "iter"))]
214 pub use super::linux::m68k::ErrnoIter;
215}
216#[cfg(all(target_os = "linux", target_arch = "m68k"))]
217pub use m68k::Errno;
218#[cfg(all(any(feature = "iter", doc), target_os = "linux", target_arch = "m68k"))]
219pub use m68k::ErrnoIter;
220
221#[cfg(any(
222 all(target_os = "linux", target_arch = "riscv32"),
223 feature = "riscv32",
224 doc
225))]
226pub mod riscv32 {
227 pub use super::linux::riscv::Errno;
229 #[cfg(any(doc, feature = "iter"))]
230 pub use super::linux::riscv::ErrnoIter;
231}
232#[cfg(all(target_os = "linux", target_arch = "riscv32"))]
233pub use riscv32::Errno;
234#[cfg(all(
235 any(feature = "iter", doc),
236 target_os = "linux",
237 target_arch = "riscv32"
238))]
239pub use riscv32::ErrnoIter;
240
241#[cfg(any(
242 all(target_os = "linux", target_arch = "riscv64"),
243 feature = "riscv64",
244 doc
245))]
246pub mod riscv64 {
247 pub use super::linux::riscv::Errno;
249 #[cfg(any(doc, feature = "iter"))]
250 pub use super::linux::riscv::ErrnoIter;
251}
252#[cfg(all(target_os = "linux", target_arch = "riscv64"))]
253pub use riscv64::Errno;
254#[cfg(all(
255 any(feature = "iter", doc),
256 target_os = "linux",
257 target_arch = "riscv64"
258))]
259pub use riscv64::ErrnoIter;
260
261#[cfg(any(
262 all(target_os = "linux", target_arch = "sparc"),
263 feature = "sparc",
264 doc
265))]
266pub mod sparc {
267 pub use super::linux::sparc::Errno;
269 #[cfg(any(doc, feature = "iter"))]
270 pub use super::linux::sparc::ErrnoIter;
271}
272#[cfg(all(target_os = "linux", target_arch = "sparc"))]
273pub use sparc::Errno;
274#[cfg(all(any(feature = "iter", doc), target_os = "linux", target_arch = "sparc"))]
275pub use sparc::ErrnoIter;
276
277#[cfg(any(
278 all(target_os = "linux", target_arch = "sparc64"),
279 feature = "sparc64",
280 doc
281))]
282pub mod sparc64 {
283 pub use super::linux::sparc::Errno;
285 #[cfg(any(doc, feature = "iter"))]
286 pub use super::linux::sparc::ErrnoIter;
287}
288#[cfg(all(target_os = "linux", target_arch = "sparc64"))]
289pub use sparc64::Errno;
290#[cfg(all(
291 any(feature = "iter", doc),
292 target_os = "linux",
293 target_arch = "sparc64"
294))]
295pub use sparc64::ErrnoIter;
296
297#[cfg(any(
298 all(target_os = "linux", target_arch = "loongarch64"),
299 feature = "loongarch64",
300 doc
301))]
302pub mod loongarch64 {
303 pub use super::linux::loongarch::Errno;
305 #[cfg(any(doc, feature = "iter"))]
306 pub use super::linux::loongarch::ErrnoIter;
307}
308#[cfg(all(target_os = "linux", target_arch = "loongarch64"))]
309pub use loongarch64::Errno;
310#[cfg(all(
311 any(feature = "iter", doc),
312 target_os = "linux",
313 target_arch = "loongarch64"
314))]
315pub use loongarch64::ErrnoIter;
316
317#[cfg(all(
318 any(
319 all(
320 any(target_os = "linux", target_os = "android"),
321 any(
322 target_arch = "x86",
323 target_arch = "x86_64",
324 target_arch = "arm",
325 target_arch = "aarch64"
326 )
327 ),
328 all(
329 any(
330 target_arch = "hexagon",
331 target_arch = "s390x",
332 target_arch = "powerpc",
333 target_arch = "powerpc64",
334 target_arch = "mips",
335 target_arch = "mips64",
336 target_arch = "m68k",
337 target_arch = "riscv32",
338 target_arch = "riscv64",
339 target_arch = "sparc",
340 target_arch = "sparc64",
341 target_arch = "loongarch64"
342 ),
343 target_os = "linux"
344 )
345 ),
346 any(feature = "libc-compat", doc)
347))]
348#[link(name = "c")]
349extern "C" {
350 #[cfg_attr(target_os = "linux", link_name = "__errno_location")]
351 #[cfg_attr(target_os = "android", link_name = "__errno")]
352 fn errno() -> *mut i32;
353}
354
355#[cfg(all(
356 any(
357 all(
358 any(target_os = "linux", target_os = "android"),
359 any(
360 target_arch = "x86",
361 target_arch = "x86_64",
362 target_arch = "arm",
363 target_arch = "aarch64"
364 )
365 ),
366 all(
367 any(
368 target_arch = "hexagon",
369 target_arch = "s390x",
370 target_arch = "powerpc",
371 target_arch = "powerpc64",
372 target_arch = "mips",
373 target_arch = "mips64",
374 target_arch = "m68k",
375 target_arch = "riscv32",
376 target_arch = "riscv64",
377 target_arch = "sparc",
378 target_arch = "sparc64",
379 target_arch = "loongarch64"
380 ),
381 target_os = "linux"
382 )
383 ),
384 any(feature = "libc-compat", doc)
385))]
386impl Errno {
387 pub fn last_os_error() -> Self {
389 Self(unsafe { *errno() })
390 }
391}
392
393#[cfg(any(
394 all(
395 any(target_os = "linux", target_os = "android"),
396 any(
397 target_arch = "x86",
398 target_arch = "x86_64",
399 target_arch = "arm",
400 target_arch = "aarch64"
401 )
402 ),
403 all(
404 any(
405 target_arch = "hexagon",
406 target_arch = "s390x",
407 target_arch = "powerpc",
408 target_arch = "powerpc64",
409 target_arch = "mips",
410 target_arch = "mips64",
411 target_arch = "m68k",
412 target_arch = "riscv32",
413 target_arch = "riscv64",
414 target_arch = "sparc",
415 target_arch = "sparc64",
416 target_arch = "loongarch64"
417 ),
418 target_os = "linux"
419 )
420))]
421#[test]
422fn basic() {
423 #[cfg(feature = "libc-compat")]
424 {
425 let _ = Errno::last_os_error();
426 }
427 let _ = Errno::EINVAL;
428}