all: simplify handling of Errno values
This commit is contained in:
parent
9c605df692
commit
34914eccb0
58 changed files with 443 additions and 464 deletions
|
|
@ -1,17 +1,17 @@
|
|||
use {
|
||||
crate::utils::oserror::OsError,
|
||||
crate::utils::oserror::{OsError, OsErrorExt},
|
||||
smallvec::{SmallVec, smallvec_inline},
|
||||
uapi::{Errno, c},
|
||||
uapi::c,
|
||||
};
|
||||
|
||||
#[cfg_attr(not(feature = "it"), expect(dead_code))]
|
||||
pub fn num_cpus() -> Result<u32, OsError> {
|
||||
let mut buf: SmallVec<[usize; 32]> = smallvec_inline![0; 32];
|
||||
loop {
|
||||
match uapi::sched_getaffinity(0, &mut buf) {
|
||||
match uapi::sched_getaffinity(0, &mut buf).to_os_error() {
|
||||
Ok(_) => return Ok(count(&buf)),
|
||||
Err(Errno(c::EINVAL)) => buf.extend_from_slice(&[0; 32][..]),
|
||||
Err(e) => return Err(e.into()),
|
||||
Err(OsError(c::EINVAL)) => buf.extend_from_slice(&[0; 32][..]),
|
||||
Err(e) => return Err(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue