Skip to content

Commit a9d5aa1

Browse files
committed
Add fallback for home_dir_crt
just returns `None` if unsupported
1 parent 0500cf9 commit a9d5aa1

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
@@ -501,3 +501,33 @@ compat_fn_with_fallback! {
501501
}
502502
#[cfg(target_vendor = "rust9x")]
503503
pub use self::SystemFunction036 as RtlGenRandom;
504+
505+
#[cfg(target_vendor = "rust9x")]
506+
compat_fn_with_fallback! {
507+
pub static userenv: &CStr = c"userenv" => { load: true, unicows: false };
508+
// >= NT 4.0
509+
// https://learn.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectoryw
510+
pub fn GetUserProfileDirectoryW(
511+
htoken: HANDLE,
512+
lpprofiledir: PWSTR,
513+
lpcchsize: *mut u32
514+
) -> BOOL {
515+
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); };
516+
FALSE
517+
}
518+
}
519+
520+
#[cfg(target_vendor = "rust9x")]
521+
compat_fn_with_fallback! {
522+
pub static advapi32: &CStr = c"advapi32" => { load: true, unicows: false };
523+
// >= NT
524+
// https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-openprocesstoken
525+
pub fn OpenProcessToken(
526+
processhandle: HANDLE,
527+
desiredaccess: TOKEN_ACCESS_MASK,
528+
tokenhandle: *mut HANDLE
529+
) -> BOOL {
530+
unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as u32); };
531+
FALSE
532+
}
533+
}

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)