Skip to main content

nd_300/platform/
mod.rs

1// Platform abstraction layer
2// Individual diagnostics handle their own platform-specific code via #[cfg] attributes.
3// This module provides shared utilities for platform detection and common operations.
4
5pub fn platform_name() -> &'static str {
6    #[cfg(windows)]
7    {
8        "Windows"
9    }
10
11    #[cfg(target_os = "macos")]
12    {
13        "macOS"
14    }
15
16    #[cfg(target_os = "linux")]
17    {
18        "Linux"
19    }
20
21    #[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
22    {
23        "Unknown"
24    }
25}
26
27pub fn is_elevated() -> bool {
28    #[cfg(windows)]
29    {
30        is_elevated_windows()
31    }
32
33    #[cfg(unix)]
34    {
35        unsafe { libc::geteuid() == 0 }
36    }
37}
38
39#[cfg(windows)]
40fn is_elevated_windows() -> bool {
41    // Check if running as administrator
42    use std::process::Command;
43    match Command::new("net").args(["session"]).output() {
44        Ok(output) => output.status.success(),
45        Err(_) => false,
46    }
47}