mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-01 13:01:21 -03:00
Remove uses of LC_GLOBAL_LOCALE
We only use this 1. if we have localeconv_l 2. to get the decimal point / thousands separator for numbers So we can ignore all this and directly create a purely LC_NUMERIC locale. This *was* more useful when we were in C++ and the printing functions all relied on locale, but we only use this in printf and that only extracts the number stuff.
This commit is contained in:
13
src/libc.c
13
src/libc.c
@@ -8,11 +8,6 @@
|
||||
#include <term.h>
|
||||
#include <unistd.h>
|
||||
|
||||
// LC_GLOBAL_LOCALE and locale_t are in xlocale.h on macOS
|
||||
#ifdef __APPLE__
|
||||
#include <xlocale.h>
|
||||
#endif
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
|
||||
size_t C_MB_CUR_MAX() { return MB_CUR_MAX; }
|
||||
@@ -186,11 +181,3 @@ int C_RLIMIT_NTHR() {
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,3 @@ pub fn $cvar() -> $type {
|
||||
fn C_RLIMIT_NPTS() -> i32; // ifndef: -1
|
||||
fn C_RLIMIT_NTHR() -> i32; // ifndef: -1
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
pub fn C_LC_GLOBAL_LOCALE() -> libc::locale_t;
|
||||
}
|
||||
|
||||
@@ -65,18 +65,17 @@ unsafe fn read_locale() -> Option<Locale> {
|
||||
extern "C" {
|
||||
fn localeconv_l(loc: libc::locale_t) -> *const libc::lconv;
|
||||
}
|
||||
let LC_GLOBAL_LOCALE: libc::locale_t = unsafe { crate::libc::C_LC_GLOBAL_LOCALE() };
|
||||
|
||||
const empty: [libc::c_char; 1] = [0];
|
||||
let cur = libc::duplocale(LC_GLOBAL_LOCALE);
|
||||
if cur.is_null() {
|
||||
return None;
|
||||
}
|
||||
// Note that, counter-intuitively, newlocale() frees 'cur'.
|
||||
let loc = libc::newlocale(libc::LC_NUMERIC_MASK, empty.as_ptr(), cur);
|
||||
|
||||
// We create a new locale (pass 0 locale_t base)
|
||||
// and pass no "locale", so everything else is taken from the environment.
|
||||
// This is fine because we're only using this for numbers.
|
||||
let loc = libc::newlocale(libc::LC_NUMERIC_MASK, empty.as_ptr(), 0 as libc::locale_t);
|
||||
if loc.is_null() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let lconv = localeconv_l(loc);
|
||||
let result = if lconv.is_null() {
|
||||
None
|
||||
|
||||
Reference in New Issue
Block a user