diff options
Diffstat (limited to 'third_party/rust/whatsys/src/windows.rs')
-rw-r--r-- | third_party/rust/whatsys/src/windows.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/third_party/rust/whatsys/src/windows.rs b/third_party/rust/whatsys/src/windows.rs new file mode 100644 index 0000000000..07ae21dd56 --- /dev/null +++ b/third_party/rust/whatsys/src/windows.rs @@ -0,0 +1,31 @@ +use libc::c_char; +use std::{ffi, ptr}; + +extern "C" { + fn get_os_release() -> *const c_char; + fn str_free(ptr: *const c_char); +} + +/// Get the version of the currently running kernel. +/// +/// **Note**: On Windows 8 and later this will report the Windows 8 OS version value `6.2`, +/// unless the final application is build to explicitly target Windows 10. +/// See [`GetVersionEx`] for details. +/// +/// [`GetVersionEx`]: https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getversionexa +/// +/// +/// Returns `None` if an error occured. +pub fn kernel_version() -> Option<String> { + unsafe { + let rp = get_os_release(); + if rp == ptr::null() { + None + } else { + let typ = ffi::CStr::from_ptr(rp); + let res = Some(typ.to_string_lossy().into_owned()); + str_free(rp); + res + } + } +} |