summaryrefslogtreecommitdiffstats
path: root/third_party/rust/whatsys/src/windows.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /third_party/rust/whatsys/src/windows.rs
parentInitial commit. (diff)
downloadfirefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz
firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/whatsys/src/windows.rs')
-rw-r--r--third_party/rust/whatsys/src/windows.rs31
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
+ }
+ }
+}