Make LC_GLOBAL_LOCALE shim less brittle

Make sure the function is defined on all platforms, and don't split conditional
compilation logic between C and rust.
This commit is contained in:
Mahmoud Al-Qudsi 2024-02-01 13:15:51 -06:00
parent a9a70e0149
commit 5169302303
2 changed files with 4 additions and 6 deletions

View file

@ -182,8 +182,10 @@ int C_RLIMIT_NTHR() {
#endif
}
#ifdef LC_GLOBAL_LOCALE
locale_t C_LC_GLOBAL_LOCALE() {
// LC_GLOBAL_LOCALE is usually -1, but not always (e.g. under NetBSD).
#ifdef LC_GLOBAL_LOCALE
return LC_GLOBAL_LOCALE;
}
#endif
return (locale_t)-1;
}

View file

@ -65,11 +65,7 @@ unsafe fn read_locale() -> Option<Locale> {
extern "C" {
fn localeconv_l(loc: libc::locale_t) -> *const libc::lconv;
}
/// Rust libc does not provide LC_GLOBAL_LOCALE, but it is usually -1.
#[cfg(not(target_os = "netbsd"))]
const LC_GLOBAL_LOCALE: libc::locale_t = (-1_isize) as libc::locale_t;
// On NetBSD it's not.
#[cfg(target_os = "netbsd")]
let LC_GLOBAL_LOCALE: libc::locale_t = unsafe { crate::libc::C_LC_GLOBAL_LOCALE() };
const empty: [libc::c_char; 1] = [0];