1#[cfg(unix)]
6pub mod invoking_user;
7
8pub fn platform_name() -> &'static str {
9 #[cfg(windows)]
10 {
11 "Windows"
12 }
13
14 #[cfg(target_os = "macos")]
15 {
16 "macOS"
17 }
18
19 #[cfg(target_os = "linux")]
20 {
21 "Linux"
22 }
23
24 #[cfg(not(any(windows, target_os = "macos", target_os = "linux")))]
25 {
26 "Unknown"
27 }
28}
29
30pub fn is_elevated() -> bool {
31 #[cfg(windows)]
32 {
33 is_elevated_windows()
34 }
35
36 #[cfg(unix)]
37 {
38 unsafe { libc::geteuid() == 0 }
39 }
40}
41
42#[cfg(windows)]
43fn is_elevated_windows() -> bool {
44 use std::process::Command;
46 match Command::new("net").args(["session"]).output() {
47 Ok(output) => output.status.success(),
48 Err(_) => false,
49 }
50}