shell_rs/arch.rs
1// Copyright (c) 2021 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
2// Use of this source is governed by Apache-2.0 License that can be found
3// in the LICENSE file.
4
5use crate::core::arch::Arch;
6use crate::core::str::cstr_to_str;
7use crate::error::Error;
8
9pub fn arch() -> Result<Arch, Error> {
10 let mut uts = nc::utsname_t::default();
11 let _ = unsafe { nc::uname(&mut uts)? };
12 let machine = cstr_to_str(&uts.machine)?;
13 machine.parse::<Arch>()
14}
15
16#[cfg(test)]
17mod tests {
18 use super::*;
19
20 #[test]
21 fn test_arch() {
22 let arch = arch();
23 assert!(arch.is_ok());
24 }
25}