1 | // Take a look at the license at the top of the repository in the LICENSE file. |
2 | |
3 | #[cfg (feature = "debug" )] |
4 | #[doc (hidden)] |
5 | #[allow (unused)] |
6 | macro_rules! sysinfo_debug { |
7 | ($($x:tt)*) => {{ |
8 | eprintln!($($x)*); |
9 | }} |
10 | } |
11 | |
12 | #[cfg (not(feature = "debug" ))] |
13 | #[doc (hidden)] |
14 | #[allow (unused)] |
15 | macro_rules! sysinfo_debug { |
16 | ($($x:tt)*) => {{}}; |
17 | } |
18 | |
19 | macro_rules! declare_signals { |
20 | ($kind:ty, _ => None,) => ( |
21 | use crate::Signal; |
22 | |
23 | pub(crate) const fn supported_signals() -> &'static [Signal] { |
24 | &[] |
25 | } |
26 | ); |
27 | |
28 | ($kind:ty, $(Signal::$signal:ident => $map:expr,)+ _ => None,) => ( |
29 | use crate::Signal; |
30 | |
31 | pub(crate) const fn supported_signals() -> &'static [Signal] { |
32 | &[$(Signal::$signal,)*] |
33 | } |
34 | |
35 | #[inline] |
36 | pub(crate) fn convert_signal(s: Signal) -> Option<$kind> { |
37 | match s { |
38 | $(Signal::$signal => Some($map),)* |
39 | _ => None, |
40 | } |
41 | } |
42 | ); |
43 | |
44 | ($kind:ty, $(Signal::$signal:ident => $map:expr,)+) => ( |
45 | use crate::Signal; |
46 | |
47 | pub(crate) const fn supported_signals() -> &'static [Signal] { |
48 | &[$(Signal::$signal,)*] |
49 | } |
50 | |
51 | #[inline] |
52 | pub(crate) fn convert_signal(s: Signal) -> Option<$kind> { |
53 | match s { |
54 | $(Signal::$signal => Some($map),)* |
55 | } |
56 | } |
57 | ) |
58 | } |
59 | |
60 | #[cfg (all(unix, not(feature = "unknown-ci" )))] |
61 | macro_rules! retry_eintr { |
62 | (set_to_0 => $($t:tt)+) => {{ |
63 | let errno = crate::libc_errno(); |
64 | if !errno.is_null() { |
65 | *errno = 0; |
66 | } |
67 | retry_eintr!($($t)+) |
68 | }}; |
69 | ($errno_value:ident => $($t:tt)+) => {{ |
70 | loop { |
71 | let ret = $($t)+; |
72 | if ret < 0 { |
73 | let tmp = std::io::Error::last_os_error(); |
74 | if tmp.kind() == std::io::ErrorKind::Interrupted { |
75 | continue; |
76 | } |
77 | $errno_value = tmp.raw_os_error().unwrap_or(0); |
78 | } |
79 | break ret; |
80 | } |
81 | }}; |
82 | ($($t:tt)+) => {{ |
83 | loop { |
84 | let ret = $($t)+; |
85 | if ret < 0 && std::io::Error::last_os_error().kind() == std::io::ErrorKind::Interrupted { |
86 | continue; |
87 | } |
88 | break ret; |
89 | } |
90 | }}; |
91 | } |
92 | |