aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/builtin_printf.cpp
diff options
context:
space:
mode:
authorGravatar Kurtis Rader <krader@skepticism.us>2016-06-03 19:05:13 -0700
committerGravatar Kurtis Rader <krader@skepticism.us>2016-06-05 15:49:34 -0700
commit0b385f145ce6144b5812bd89fa8f73369bcbe57f (patch)
tree3d3b059af2e9a7efb6fe38e33ee1782b23e6167e /src/builtin_printf.cpp
parent32a585a52b20687a1a16c45142da2261d28b7a27 (diff)
simplify, and fix, setting the current locale
Fix test setup bogosities. Specifically, they weren't hermetic with respect to locale env vars. Rewrite the handling of locale vars to simplify the code and make it more like the pattern most programs employ. Fixes #3110
Diffstat (limited to 'src/builtin_printf.cpp')
-rw-r--r--src/builtin_printf.cpp25
1 files changed, 6 insertions, 19 deletions
diff --git a/src/builtin_printf.cpp b/src/builtin_printf.cpp
index 36b8e638..d81ab453 100644
--- a/src/builtin_printf.cpp
+++ b/src/builtin_printf.cpp
@@ -197,24 +197,6 @@ static int octal_to_bin(wchar_t c) {
}
}
-double C_STRTOD(wchar_t const *nptr, wchar_t **endptr) {
- double r;
-
- const wcstring saved_locale = wsetlocale(LC_NUMERIC, NULL);
-
- if (!saved_locale.empty()) {
- wsetlocale(LC_NUMERIC, L"C");
- }
-
- r = wcstod(nptr, endptr);
-
- if (!saved_locale.empty()) {
- wsetlocale(LC_NUMERIC, saved_locale.c_str());
- }
-
- return r;
-}
-
void builtin_printf_state_t::fatal_error(const wchar_t *fmt, ...) {
// Don't error twice.
if (early_exit) return;
@@ -283,7 +265,12 @@ uintmax_t raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
template <>
long double raw_string_to_scalar_type(const wchar_t *s, wchar_t **end) {
- return C_STRTOD(s, end);
+ // Forcing the locale to C is questionable but it's what the old C_STRTOD() that I inlined here
+ // as part of changing how locale management is done by fish.
+ char * old_locale = setlocale(LC_NUMERIC, "C");
+ double val = wcstod(s, end);
+ setlocale(LC_NUMERIC, old_locale);
+ return val;
}
template <typename T>