|
3 | 3 | #[cfg(not(feature = "uefi"))] |
4 | 4 | use std::{thread, time}; |
5 | 5 |
|
| 6 | +#[cfg(feature = "uefi")] |
| 7 | +use alloc::string::{String, ToString}; |
| 8 | + |
| 9 | +// Could report the implemented UEFI spec version |
| 10 | +// But that's not very useful. Just look at the BIOS version |
| 11 | +// But at least it's useful to see that the tool was run on UEFI |
| 12 | +#[cfg(feature = "uefi")] |
| 13 | +pub fn get_os_version() -> String { |
| 14 | + "UEFI".to_string() |
| 15 | +} |
| 16 | + |
| 17 | +#[cfg(target_family = "windows")] |
| 18 | +pub fn get_os_version() -> String { |
| 19 | + let ver = windows_version::OsVersion::current(); |
| 20 | + format!("{}.{}.{}.{}", ver.major, ver.minor, ver.pack, ver.build) |
| 21 | +} |
| 22 | + |
| 23 | +#[cfg(target_family = "unix")] |
| 24 | +pub fn get_os_version() -> String { |
| 25 | + if let Ok(uts) = nix::sys::utsname::uname() { |
| 26 | + // uname -a without hostname |
| 27 | + format!( |
| 28 | + "{} {} {} {}", |
| 29 | + uts.sysname().to_string_lossy(), |
| 30 | + uts.release().to_string_lossy(), |
| 31 | + uts.version().to_string_lossy(), |
| 32 | + uts.machine().to_string_lossy(), |
| 33 | + ) |
| 34 | + } else { |
| 35 | + "Unknown".to_string() |
| 36 | + } |
| 37 | +} |
| 38 | + |
6 | 39 | /// Sleep a number of microseconds |
7 | 40 | pub fn sleep(micros: u64) { |
8 | 41 | #[cfg(not(feature = "uefi"))] |
|
0 commit comments