diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-13 18:22:45 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-13 18:22:45 +0100 |
commit | 3d695f697e7230f3b4fa8922847b20eae632226f (patch) | |
tree | 52d6907f87d0dbe07274c71430545190fbbc4d19 /src/nolocale.h | |
parent | f28bf71b7c105da7cd0a7db67e21bbceb5df8a1b (diff) |
More portable way of switching locale.
Diffstat (limited to 'src/nolocale.h')
-rw-r--r-- | src/nolocale.h | 68 |
1 files changed, 7 insertions, 61 deletions
diff --git a/src/nolocale.h b/src/nolocale.h index d61abbb..816dd9c 100644 --- a/src/nolocale.h +++ b/src/nolocale.h @@ -34,27 +34,11 @@ static inline double atof_nol(const char *nptr) { double res; -#ifdef WIN32 + const char *locale = setlocale(LC_NUMERIC, "C"); - _locale_t l = _create_locale(LC_NUMERIC, "C"); + res = atof(nptr); - res = _atof_l(nptr, l); - - _free_locale(l); - -#else/*WIN32*/ - - locale_t new_locale, prev_locale; - - new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); - prev_locale = uselocale(new_locale); - - res = atof(nptr); - - uselocale(prev_locale); - freelocale(new_locale); - -#endif/*WIN32*/ + setlocale(LC_NUMERIC, locale); return res; } @@ -63,33 +47,14 @@ static inline int sprintf_nol(char *str, const char *format, ...) { int ret; -#ifdef WIN32 - - _locale_t l = _create_locale(LC_NUMERIC, "C"); - - va_list vl; - va_start(vl, format); - ret = _vsprintf_l(str, format, l, vl); - va_end(vl); - - _free_locale(l); - -#else/*WIN32*/ - - locale_t new_locale, prev_locale; - - new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); - prev_locale = uselocale(new_locale); + const char *locale = setlocale(LC_NUMERIC, "C"); va_list vl; va_start(vl, format); ret = vsprintf(str, format, vl); va_end(vl); - uselocale(prev_locale); - freelocale(new_locale); - -#endif/*WIN32*/ + setlocale(LC_NUMERIC, locale); return ret; } @@ -98,33 +63,14 @@ static inline int snprintf_nol(char *str, size_t size, const char *format, ...) { int ret; -#ifdef WIN32 - - _locale_t l = _create_locale(LC_NUMERIC, "C"); - - va_list vl; - va_start(vl, format); - ret = _vsnprintf_l(str, size, format, l, vl); - va_end(vl); - - _free_locale(l); - -#else/*WIN32*/ - - locale_t new_locale, prev_locale; - - new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); - prev_locale = uselocale(new_locale); + const char *locale = setlocale(LC_NUMERIC, "C"); va_list vl; va_start(vl, format); ret = vsnprintf(str, size, format, vl); va_end(vl); - uselocale(prev_locale); - freelocale(new_locale); - -#endif/*WIN32*/ + setlocale(LC_NUMERIC, locale); return ret; } |