1pub const EPERM: i32 = 1;
3
4pub const ENOENT: i32 = 2;
6
7pub const ESRCH: i32 = 3;
9
10pub const EINTR: i32 = 4;
12
13pub const EIO: i32 = 5;
15
16pub const ENXIO: i32 = 6;
18
19pub const E2BIG: i32 = 7;
21
22pub const ENOEXEC: i32 = 8;
24
25pub const EBADF: i32 = 9;
27
28pub const ECHILD: i32 = 10;
30
31pub const EAGAIN: i32 = 11;
33
34pub const ENOMEM: i32 = 12;
36
37pub const EACCES: i32 = 13;
39
40pub const EFAULT: i32 = 14;
42
43pub const ENOTBLK: i32 = 15;
45
46pub const EBUSY: i32 = 16;
48
49pub const EEXIST: i32 = 17;
51
52pub const EXDEV: i32 = 18;
54
55pub const ENODEV: i32 = 19;
57
58pub const ENOTDIR: i32 = 20;
60
61pub const EISDIR: i32 = 21;
63
64pub const EINVAL: i32 = 22;
66
67pub const ENFILE: i32 = 23;
69
70pub const EMFILE: i32 = 24;
72
73pub const ENOTTY: i32 = 25;
75
76pub const ETXTBSY: i32 = 26;
78
79pub const EFBIG: i32 = 27;
81
82pub const ENOSPC: i32 = 28;
84
85pub const ESPIPE: i32 = 29;
87
88pub const EROFS: i32 = 30;
90
91pub const EMLINK: i32 = 31;
93
94pub const EPIPE: i32 = 32;
96
97pub const EDOM: i32 = 33;
99
100pub const ERANGE: i32 = 34;
102
103pub const EDEADLK: i32 = 35;
105
106pub const ENAMETOOLONG: i32 = 36;
108
109pub const ENOLCK: i32 = 37;
111
112pub const ENOSYS: i32 = 38;
114
115pub const ENOTEMPTY: i32 = 39;
117
118pub const ELOOP: i32 = 40;
120
121pub const EWOULDBLOCK: i32 = EAGAIN;
123
124pub const ENOMSG: i32 = 42;
126
127pub const EIDRM: i32 = 43;
129
130pub const ECHRNG: i32 = 44;
132
133pub const EL2NSYNC: i32 = 45;
135
136pub const EL3HLT: i32 = 46;
138
139pub const EL3RST: i32 = 47;
141
142pub const ELNRNG: i32 = 48;
144
145pub const EUNATCH: i32 = 49;
147
148pub const ENOCSI: i32 = 50;
150
151pub const EL2HLT: i32 = 51;
153
154pub const EBADE: i32 = 52;
156
157pub const EBADR: i32 = 53;
159
160pub const EXFULL: i32 = 54;
162
163pub const ENOANO: i32 = 55;
165
166pub const EBADRQC: i32 = 56;
168
169pub const EBADSLT: i32 = 57;
171
172pub const EDEADLOCK: i32 = EDEADLK;
173
174pub const EBFONT: i32 = 59;
176
177pub const ENOSTR: i32 = 60;
179
180pub const ENODATA: i32 = 61;
182
183pub const ETIME: i32 = 62;
185
186pub const ENOSR: i32 = 63;
188
189pub const ENONET: i32 = 64;
191
192pub const ENOPKG: i32 = 65;
194
195pub const EREMOTE: i32 = 66;
197
198pub const ENOLINK: i32 = 67;
200
201pub const EADV: i32 = 68;
203
204pub const ESRMNT: i32 = 69;
206
207pub const ECOMM: i32 = 70;
209
210pub const EPROTO: i32 = 71;
212
213pub const EMULTIHOP: i32 = 72;
215
216pub const EDOTDOT: i32 = 73;
218
219pub const EBADMSG: i32 = 74;
221
222pub const EOVERFLOW: i32 = 75;
224
225pub const ENOTUNIQ: i32 = 76;
227
228pub const EBADFD: i32 = 77;
230
231pub const EREMCHG: i32 = 78;
233
234pub const ELIBACC: i32 = 79;
236
237pub const ELIBBAD: i32 = 80;
239
240pub const ELIBSCN: i32 = 81;
242
243pub const ELIBMAX: i32 = 82;
245
246pub const ELIBEXEC: i32 = 83;
248
249pub const EILSEQ: i32 = 84;
251
252pub const ERESTART: i32 = 85;
254
255pub const ESTRPIPE: i32 = 86;
257
258pub const EUSERS: i32 = 87;
260
261pub const ENOTSOCK: i32 = 88;
263
264pub const EDESTADDRREQ: i32 = 89;
266
267pub const EMSGSIZE: i32 = 90;
269
270pub const EPROTOTYPE: i32 = 91;
272
273pub const ENOPROTOOPT: i32 = 92;
275
276pub const EPROTONOSUPPORT: i32 = 93;
278
279pub const ESOCKTNOSUPPORT: i32 = 94;
281
282pub const EOPNOTSUPP: i32 = 95;
284
285pub const EPFNOSUPPORT: i32 = 96;
287
288pub const EAFNOSUPPORT: i32 = 97;
290
291pub const EADDRINUSE: i32 = 98;
293
294pub const EADDRNOTAVAIL: i32 = 99;
296
297pub const ENETDOWN: i32 = 100;
299
300pub const ENETUNREACH: i32 = 101;
302
303pub const ENETRESET: i32 = 102;
305
306pub const ECONNABORTED: i32 = 103;
308
309pub const ECONNRESET: i32 = 104;
311
312pub const ENOBUFS: i32 = 105;
314
315pub const EISCONN: i32 = 106;
317
318pub const ENOTCONN: i32 = 107;
320
321pub const ESHUTDOWN: i32 = 108;
323
324pub const ETOOMANYREFS: i32 = 109;
326
327pub const ETIMEDOUT: i32 = 110;
329
330pub const ECONNREFUSED: i32 = 111;
332
333pub const EHOSTDOWN: i32 = 112;
335
336pub const EHOSTUNREACH: i32 = 113;
338
339pub const EALREADY: i32 = 114;
341
342pub const EINPROGRESS: i32 = 115;
344
345pub const ESTALE: i32 = 116;
347
348pub const EUCLEAN: i32 = 117;
350
351pub const ENOTNAM: i32 = 118;
353
354pub const ENAVAIL: i32 = 119;
356
357pub const EISNAM: i32 = 120;
359
360pub const EREMOTEIO: i32 = 121;
362
363pub const EDQUOT: i32 = 122;
365
366pub const ENOMEDIUM: i32 = 123;
368
369pub const EMEDIUMTYPE: i32 = 124;
371
372pub const ECANCELED: i32 = 125;
374
375pub const ENOKEY: i32 = 126;
377
378pub const EKEYEXPIRED: i32 = 127;
380
381pub const EKEYREVOKED: i32 = 128;
383
384pub const EKEYREJECTED: i32 = 129;
386
387pub const EOWNERDEAD: i32 = 130;
389
390pub const ENOTRECOVERABLE: i32 = 131;
392
393pub const ERFKILL: i32 = 132;
395
396pub const EHWPOISON: i32 = 133;
398
399#[cfg(all(
401 not(any(feature = "common-os", feature = "nostd")),
402 not(target_arch = "riscv64")
403))]
404#[unsafe(no_mangle)]
405#[linkage = "weak"]
406pub extern "C" fn sys_errno_location() -> *mut i32 {
407 use core::cell::UnsafeCell;
408
409 #[thread_local]
410 static ERRNO: UnsafeCell<i32> = UnsafeCell::new(0);
411
412 ERRNO.get()
413}
414
415#[cfg(not(feature = "nostd"))]
419#[unsafe(no_mangle)]
420pub extern "C" fn sys_get_errno() -> i32 {
421 sys_errno()
422}
423
424#[cfg(not(feature = "nostd"))]
428#[unsafe(no_mangle)]
429pub extern "C" fn sys_errno() -> i32 {
430 cfg_if::cfg_if! {
431 if #[cfg(any(feature = "common-os", target_arch = "riscv64"))] {
432 0
433 } else {
434 unsafe { *sys_errno_location() }
435 }
436 }
437}
438
439pub(crate) trait ToErrno {
440 fn to_errno(&self) -> Option<i32> {
441 None
442 }
443
444 fn set_errno(self) -> Self
445 where
446 Self: Sized,
447 {
448 if let Some(errno) = self.to_errno() {
449 cfg_if::cfg_if! {
450 if #[cfg(any(feature = "common-os", feature = "nostd", target_arch = "riscv64"))] {
451 let _ = errno;
452 } else {
453 unsafe {
454 *sys_errno_location() = errno;
455 }
456 }
457 }
458 }
459 self
460 }
461}
462
463impl ToErrno for i32 {
464 fn to_errno(&self) -> Option<i32> {
465 (*self < 0).then_some(-self)
466 }
467}
468
469impl ToErrno for i64 {
470 fn to_errno(&self) -> Option<i32> {
471 (*self < 0).then(|| i32::try_from(-self).unwrap())
472 }
473}
474
475impl ToErrno for isize {
476 fn to_errno(&self) -> Option<i32> {
477 (*self < 0).then(|| i32::try_from(-self).unwrap())
478 }
479}
480
481impl ToErrno for u8 {}
482impl ToErrno for u16 {}
483impl ToErrno for u32 {}
484impl ToErrno for usize {}
485impl ToErrno for *mut u8 {}
486impl ToErrno for () {}
487impl ToErrno for ! {}