From da2d01a87c911f0db602e8e4376bb485fdfc31f1 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 13 Feb 2015 14:59:09 +0100 Subject: Possible win32 fix for missing locale_t type - part2. --- src/nolocale.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/src/nolocale.h b/src/nolocale.h index f8a5303..1b71ef2 100644 --- a/src/nolocale.h +++ b/src/nolocale.h @@ -30,13 +30,20 @@ #include #include -#ifdef WIN32 -typedef _locale_t locale_t; -#endif - static inline double atof_nol(const char *nptr) { double res; + +#ifdef WIN32 + + _locale_t l = _create_locale(LC_NUMERIC_MASK, "C"); + + res = _atof_l(nptr, l); + + _free_locale(l); + +#else/*WIN32*/ + locale_t new_locale, prev_locale; new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); @@ -47,11 +54,28 @@ static inline double atof_nol(const char *nptr) uselocale(prev_locale); freelocale(new_locale); +#endif/*WIN32*/ + return res; } static inline int sprintf_nol(char *str, const char *format, ...) { + int ret; + +#ifdef WIN32 + + _locale_t l = _create_locale(LC_NUMERIC_MASK, "C"); + + va_list vl; + va_start(vl, format); + ret = _vsprintf_l(str, format, vl, l); + va_end(vl); + + _free_locale(l); + +#else/*WIN32*/ + locale_t new_locale, prev_locale; new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); @@ -59,17 +83,34 @@ static inline int sprintf_nol(char *str, const char *format, ...) va_list vl; va_start(vl, format); - int ret = vsprintf(str, format, vl); + ret = vsprintf(str, format, vl); va_end(vl); uselocale(prev_locale); freelocale(new_locale); +#endif/*WIN32*/ + return ret; } static inline int snprintf_nol(char *str, size_t size, const char *format, ...) { + int ret; + +#ifdef WIN32 + + _locale_t l = _create_locale(LC_NUMERIC_MASK, "C"); + + va_list vl; + va_start(vl, format); + ret = vsnprintf(str, size, format, vl, l); + va_end(vl); + + _free_locale(l); + +#else/*WIN32*/ + locale_t new_locale, prev_locale; new_locale = newlocale(LC_NUMERIC_MASK, "C", NULL); @@ -77,12 +118,14 @@ static inline int snprintf_nol(char *str, size_t size, const char *format, ...) va_list vl; va_start(vl, format); - int ret = vsnprintf(str, size, format, vl); + ret = vsnprintf(str, size, format, vl); va_end(vl); uselocale(prev_locale); freelocale(new_locale); +#endif/*WIN32*/ + return ret; } -- cgit v1.2.3