zeroshade commented on code in PR #3099: URL: https://github.com/apache/arrow-adbc/pull/3099#discussion_r2198840904
########## rust/core/src/driver_manager.rs: ########## @@ -1310,3 +1645,506 @@ impl Drop for ManagedStatement { unsafe { method(statement.deref_mut(), null_mut()) }; } } + +#[cfg(target_os = "windows")] +extern crate windows_sys as windows; + +#[cfg(target_os = "windows")] +mod target_windows { + use std::ffi::c_void; + use std::ffi::OsString; + use std::os::windows::ffi::OsStringExt; + use std::path::PathBuf; + use std::slice; + + use super::windows::Win32::UI::Shell; + + // adapted from https://github.com/dirs-dev/dirs-sys-rs/blob/main/src/lib.rs#L150 + fn user_config_dir() -> Option<PathBuf> { + unsafe { + let mut path_ptr: windows::core::PWSTR = std::ptr::null_mut(); + let result = Shell::SHGetKnownFolderPath( + Shell::FOLDERID_LocalAppData, + 0, + std::ptr::null_mut(), + &mut path_ptr, + ); + + if result == 0 { + let len = windows::Win32::Globalization::lstrlenW(path_ptr) as usize; + let path = slice::from_raw_parts(path_ptr, len); + let ostr: OsString = OsStringExt::from_wide(path); + windows::Win32::System::Com::CoTaskMemFree(path_ptr as *const c_void); + Some(PathBuf::from(ostr)) + } else { + windows::Win32::System::Com::CoTaskMemFree(path_ptr as *const c_void); + None + } + } + } +} + +fn user_config_dir() -> Option<PathBuf> { + #[cfg(target_os = "windows")] Review Comment: after a bit of research it looks like the preferred way is the `target_os` version, so i'll standardize on that -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org