Feature-detect localeconv_l() presence

This commit is contained in:
Mahmoud Al-Qudsi 2024-01-13 14:21:14 -06:00
parent 195852b562
commit 30f70f02de
2 changed files with 8 additions and 15 deletions

View file

@ -96,6 +96,7 @@ fn detect_features(target: Target) {
),
("bsd", &detect_bsd),
("gettext", &have_gettext),
("localeconv_l", &have_localeconv_l),
] {
match handler(&target) {
Err(e) => rsconf::warn!("{}: {}", feature, e),
@ -184,3 +185,8 @@ fn have_gettext(target: &Target) -> Result<bool, Box<dyn Error>> {
}
}
}
/// See if the system headers provide the thread-safe localeconv_l(3) alternative to localeconv(3).
fn have_localeconv_l(target: &Target) -> Result<bool, Box<dyn Error>> {
Ok(target.has_symbol_in::<String>("localeconv_l", &[]))
}

View file

@ -59,14 +59,7 @@ unsafe fn lconv_to_locale(lconv: &libc::lconv) -> Locale {
}
/// Read the numeric locale, or None on any failure.
// TODO: figure out precisely which platforms have localeconv_l, or use a build script.
#[cfg(any(
target_os = "macos",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
))]
#[cfg(feature = "localeconv_l")]
unsafe fn read_locale() -> Option<Locale> {
extern "C" {
fn localeconv_l(loc: libc::locale_t) -> *const libc::lconv;
@ -95,13 +88,7 @@ unsafe fn read_locale() -> Option<Locale> {
result
}
#[cfg(not(any(
target_os = "macos",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
)))]
#[cfg(not(feature = "localeconv_l"))]
unsafe fn read_locale() -> Option<Locale> {
// Bleh, we have to go through localeconv, which races with setlocale.
// TODO: There has to be a better way to do this.