Skip to content

Commit 9bc9106

Browse files
committed
Fall back to old (broken) env arg behavior if CompareStringOrdinal is not available
See rust-lang#85270 and rust-lang#87863
1 parent 3163c9c commit 9bc9106

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

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

+16
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,19 @@ compat_fn_with_fallback! {
636636
TRUE
637637
}
638638
}
639+
640+
#[cfg(target_vendor = "rust9x")]
641+
compat_fn_with_fallback! {
642+
pub static KERNEL32: &CStr = c"kernel32" => { load: false, unicows: false };
643+
// >= Vista / Server 2008
644+
// https://learn.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
645+
pub fn CompareStringOrdinal(
646+
lpstring1: PCWSTR,
647+
cchcount1: i32,
648+
lpstring2: PCWSTR,
649+
cchcount2: i32,
650+
bignorecase: BOOL,
651+
) -> COMPARESTRING_RESULT {
652+
unimplemented!()
653+
}
654+
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ impl EnvKey {
6969
// [4] https://docs.microsoft.com/en-us/windows/win32/api/stringapiset/nf-stringapiset-comparestringordinal
7070
impl Ord for EnvKey {
7171
fn cmp(&self, other: &Self) -> cmp::Ordering {
72+
#[cfg(target_vendor = "rust9x")]
73+
{
74+
if c::CompareStringOrdinal::available().is_none() {
75+
return self.os_string.cmp(&other.os_string);
76+
}
77+
}
78+
7279
unsafe {
7380
let result = c::CompareStringOrdinal(
7481
self.utf16.as_ptr(),
@@ -120,6 +127,15 @@ impl PartialEq<str> for EnvKey {
120127
// they are compared using a caseless string mapping.
121128
impl From<OsString> for EnvKey {
122129
fn from(k: OsString) -> Self {
130+
#[cfg(target_vendor = "rust9x")]
131+
{
132+
if c::CompareStringOrdinal::available().is_none() {
133+
let mut k = k;
134+
k.make_ascii_uppercase();
135+
return EnvKey { utf16: Vec::new(), os_string: k };
136+
}
137+
}
138+
123139
EnvKey { utf16: k.encode_wide().collect(), os_string: k }
124140
}
125141
}

0 commit comments

Comments
 (0)