about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-02-18 05:06:28 +0000
committerbors <bors@rust-lang.org>2024-02-18 05:06:28 +0000
commit90fccaad801a929fc482dbbeca0231aa197de7c7 (patch)
tree2425c84d0a9356e90dde5de808e5e5456df8e8be /library/std/src
parent55f29d22b48c02f185fcfcfb34a1e3c78121cb7c (diff)
parent7a83e2f30d92748640461edbd5812e7b9229e995 (diff)
Auto merge of #3305 - rust-lang:rustup-2024-02-18, r=saethlin
Automatic Rustup
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/pal/windows/os.rs30
1 files changed, 25 insertions, 5 deletions
diff --git a/library/std/src/sys/pal/windows/os.rs b/library/std/src/sys/pal/windows/os.rs
index 829dd5eb97a..73cb2db8b79 100644
--- a/library/std/src/sys/pal/windows/os.rs
+++ b/library/std/src/sys/pal/windows/os.rs
@@ -318,13 +318,33 @@ pub fn temp_dir() -> PathBuf {
     super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
 }
 
-#[cfg(not(target_vendor = "uwp"))]
+#[cfg(all(not(target_vendor = "uwp"), not(target_vendor = "win7")))]
+fn home_dir_crt() -> Option<PathBuf> {
+    unsafe {
+        // Defined in processthreadsapi.h.
+        const CURRENT_PROCESS_TOKEN: usize = -4_isize as usize;
+
+        super::fill_utf16_buf(
+            |buf, mut sz| {
+                match c::GetUserProfileDirectoryW(
+                    ptr::invalid_mut(CURRENT_PROCESS_TOKEN),
+                    buf,
+                    &mut sz,
+                ) {
+                    0 if api::get_last_error().code != c::ERROR_INSUFFICIENT_BUFFER => 0,
+                    0 => sz,
+                    _ => sz - 1, // sz includes the null terminator
+                }
+            },
+            super::os2path,
+        )
+        .ok()
+    }
+}
+
+#[cfg(target_vendor = "win7")]
 fn home_dir_crt() -> Option<PathBuf> {
     unsafe {
-        // The magic constant -4 can be used as the token passed to GetUserProfileDirectoryW below
-        // instead of us having to go through these multiple steps to get a token. However this is
-        // not implemented on Windows 7, only Windows 8 and up. When we drop support for Windows 7
-        // we can simplify this code. See #90144 for details.
         use crate::sys::handle::Handle;
 
         let me = c::GetCurrentProcess();