diff options
| author | David Lönnhager <david.l@mullvad.net> | 2025-08-27 22:20:35 +0200 |
|---|---|---|
| committer | David Lönnhager <david.l@mullvad.net> | 2025-09-03 14:57:50 +0200 |
| commit | 9d4c2e92ec06ffaa6ca6a1cc17d10d8e79a3da93 (patch) | |
| tree | edd7539078f17b30c04be1d449ac8b197c5c3a07 /talpid-windows/src | |
| parent | 3abb6a6d990bba6e5f659dc1373955d944122c45 (diff) | |
| download | mullvadvpn-9d4c2e92ec06ffaa6ca6a1cc17d10d8e79a3da93.tar.xz mullvadvpn-9d4c2e92ec06ffaa6ca6a1cc17d10d8e79a3da93.zip | |
Move get_system_dir to talpid-windows
Diffstat (limited to 'talpid-windows/src')
| -rw-r--r-- | talpid-windows/src/env.rs | 18 | ||||
| -rw-r--r-- | talpid-windows/src/lib.rs | 3 |
2 files changed, 21 insertions, 0 deletions
diff --git a/talpid-windows/src/env.rs b/talpid-windows/src/env.rs new file mode 100644 index 0000000000..1f49307822 --- /dev/null +++ b/talpid-windows/src/env.rs @@ -0,0 +1,18 @@ +use std::io; +use std::os::windows::ffi::OsStringExt; +use std::{ffi::OsString, path::PathBuf}; + +use windows_sys::Win32::{Foundation::MAX_PATH, System::SystemInformation::GetSystemDirectoryW}; + +/// Get the system directory path. This is typically `C:\Windows\System32`. +pub fn get_system_dir() -> io::Result<PathBuf> { + let mut sysdir = [0u16; MAX_PATH as usize + 1]; + // SAFETY: We have a valid buffer and length + let len = unsafe { GetSystemDirectoryW(sysdir.as_mut_ptr(), (sysdir.len() - 1) as u32) }; + if len == 0 { + return Err(io::Error::last_os_error()); + } + Ok(PathBuf::from(OsString::from_wide( + &sysdir[0..(len as usize)], + ))) +} diff --git a/talpid-windows/src/lib.rs b/talpid-windows/src/lib.rs index bf6054ee79..27ddd877c2 100644 --- a/talpid-windows/src/lib.rs +++ b/talpid-windows/src/lib.rs @@ -3,6 +3,9 @@ #![deny(missing_docs)] #![cfg(windows)] +/// Environment +pub mod env; + /// File system pub mod fs; |
