diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-13 14:59:09 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2015-02-13 14:59:09 +0100 |
commit | da2d01a87c911f0db602e8e4376bb485fdfc31f1 (patch) | |
tree | f3587c5367dca639139cb188fa3a71466d822b88 /src/nolocale.h | |
parent | 5be85a677f8f228614d8e449674c8fe3161b3d71 (diff) |
Possible win32 fix for missing locale_t type - part2.
Diffstat (limited to 'src/nolocale.h')
-rw-r--r-- | src/nolocale.h | 55 |
1 files 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 <locale.h> #include <stdarg.h> -#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; } |