Skip to content

Commit 97f906b

Browse files
committed
Add fallback for home_dir_crt
just returns `None` if unsupported
1 parent 7cb0186 commit 97f906b

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

library/std/src/sys/pal/windows/c.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,3 +513,33 @@ compat_fn_with_fallback! {
513513
}
514514
#[cfg(target_vendor = "rust9x")]
515515
pub use self::SystemFunction036 as RtlGenRandom;
516+
517+
#[cfg(target_vendor = "rust9x")]
518+
compat_fn_with_fallback! {
519+
pub static userenv: &CStr = c"userenv" => { load: true, unicows: false };
520+
// >= NT 4.0
521+
// https://learn.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectoryw
522+
pub fn GetUserProfileDirectoryW(
523+
htoken: HANDLE,
524+
lpprofiledir: PWSTR,
525+
lpcchsize: *mut u32
526+
) -> BOOL {
527+
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); };
528+
FALSE
529+
}
530+
}
531+
532+
#[cfg(target_vendor = "rust9x")]
533+
compat_fn_with_fallback! {
534+
pub static advapi32: &CStr = c"advapi32" => { load: true, unicows: false };
535+
// >= NT
536+
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocesstoken
537+
pub fn OpenProcessToken(
538+
processhandle: HANDLE,
539+
desiredaccess: TOKEN_ACCESS_MASK,
540+
tokenhandle: *mut HANDLE
541+
) -> BOOL {
542+
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); };
543+
FALSE
544+
}
545+
}

library/std/src/sys/pal/windows/os.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ pub fn temp_dir() -> PathBuf {
320320
super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap()
321321
}
322322

323-
#[cfg(all(not(target_vendor = "uwp"), not(target_vendor = "win7")))]
323+
#[cfg(all(not(target_vendor = "uwp"), not(target_vendor = "win7"), not(target_vendor = "rust9x")))]
324324
fn home_dir_crt() -> Option<PathBuf> {
325325
unsafe {
326326
// Defined in processthreadsapi.h.
@@ -346,7 +346,7 @@ fn home_dir_crt() -> Option<PathBuf> {
346346
}
347347
}
348348

349-
#[cfg(target_vendor = "win7")]
349+
#[cfg(any(target_vendor = "win7", target_vendor = "rust9x"))]
350350
fn home_dir_crt() -> Option<PathBuf> {
351351
unsafe {
352352
use crate::sys::handle::Handle;

0 commit comments

Comments
 (0)