From 5169302303970b69572b946892dd1066da3f985e Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Thu, 1 Feb 2024 13:15:51 -0600 Subject: [PATCH] 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. --- src/libc.c | 6 ++++-- src/locale.rs | 4 ---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libc.c b/src/libc.c index b3f90cede..adef2ef84 100644 --- a/src/libc.c +++ b/src/libc.c @@ -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; +} diff --git a/src/locale.rs b/src/locale.rs index 1beff696a..0f69fa589 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -65,11 +65,7 @@ unsafe fn read_locale() -> Option { 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];