- diff --git a/Base/CMakeLists.txt b/Base/CMakeLists.txt
- index b3922e1..c789604 100644
- --- a/Base/CMakeLists.txt
- +++ b/Base/CMakeLists.txt
- @@ -25,6 +25,7 @@ set(PROJECT_SOURCE_FILES RovDate.cpp
- MessageBoxWithChangableButtons.cpp
- RCriticalSection.cpp
- Thread.cpp
- + RovLocale.cpp
- Error.cpp )
- if(WIN32)
- @@ -34,15 +35,13 @@ else(WIN32)
- if(RDE_BUILD)
- set(PROJECT_SOURCE_FILES ${PROJECT_SOURCE_FILES}
- RecursiveSemaphor.cpp
- - PosixSystem.cpp
- - RovLocale.cpp )
- + PosixSystem.cpp )
- else(RDE_BUILD)
- set(PROJECT_SOURCE_FILES ${PROJECT_SOURCE_FILES}
- TraceBack.cpp
- RovFileSystem.cpp
- RecursiveSemaphor.cpp
- - PosixSystem.cpp
- - RovLocale.cpp )
- + PosixSystem.cpp )
- endif(RDE_BUILD)
- endif(WIN32)
- diff --git a/Base/PosixSystem.hpp b/Base/PosixSystem.hpp
- index cf7e2c7..6e0acc0 100755
- --- a/Base/PosixSystem.hpp
- +++ b/Base/PosixSystem.hpp
- @@ -38,10 +38,10 @@
- #include <stdlib.h>
- #include "RecursiveSemaphor.hpp"
- #include "Error.hpp"
- +#include "RovLocale.hpp"
- #undef TEST_REALTIME
- -extern locale_t rov_get_posix_localeobj(void);
- extern void dumpBackTrace( ostream & _outStr );
- diff --git a/Base/RovLocale.cpp b/Base/RovLocale.cpp
- index afe7d2d..85d6aeb 100644
- --- a/Base/RovLocale.cpp
- +++ b/Base/RovLocale.cpp
- @@ -1,16 +1,17 @@
- ///////////////////////////////////////////////////////////////////////////////
- // RovLocale.cpp POSIX i18n/l10n support functions
- -// Copyright acontis technologies GmbH, Weingarten, Germany
- +// Copyright ROVEMA
- // Response Roland Mainz <roland.mainz@rovema.de>
- // Description Support functions for i18n and l10n
- ///////////////////////////////////////////////////////////////////////////////
- -#include "PosixSystem.hpp"
- +#include "RovLocale.hpp"
- -/*
- - * ToDo:
- - * - Add implementations of |printf_l()|/|sprintf_l()| etc.
- - */
- +extern "C" {
- +
- +#include <stdlib.h>
- +#include <stdio.h>
- +#include <pthread.h>
- static pthread_once_t posix_localeobj_init = PTHREAD_ONCE_INIT;
- static locale_t posix_localeobj = 0;
- @@ -23,7 +24,19 @@ static void init_posix_localeobj(void)
- * resources at shutdown, and only writes data to NVRAM
- * before |exit()|.
- */
- - posix_localeobj = newlocale(LC_ALL_MASK, "POSIX", (locale_t)0);
- + posix_localeobj = newlocale(LC_ALL_MASK,
- +#if EMULATE_POSIX_NEWLOCALE_ON_WINDOWS
- + "C",
- +#else
- + "POSIX",
- +#endif
- + (locale_t)0);
- +
- +#if 0
- + (void)fprintf(stderr,
- + "init_posix_localeobj: POSIX locale object %llx\n",
- + (long long)posix_localeobj);
- +#endif
- }
- locale_t rov_get_posix_localeobj(void)
- @@ -32,3 +45,85 @@ locale_t rov_get_posix_localeobj(void)
- return posix_localeobj;
- }
- +
- +/*
- + * POSIX |newlocale()|&co emulation, if the compiler environment does
- + * not provide one
- + */
- +#if EMULATE_POSIX_NEWLOCALE_ON_WINDOWS
- +
- +locale_t newlocale(int mask, const char * locale, locale_t base_not_implemented)
- +{
- + return _create_locale(mask, locale);
- +}
- +
- +locale_t uselocale(locale_t newlocobj)
- +{
- + locale_t old_locale = _get_current_locale();
- +
- + /*
- + * uselocale() sets the thread's locale by definition, so
- + * unconditionally use thread-local locale
- + */
- + (void)_configthreadlocale(_ENABLE_PER_THREAD_LOCALE);
- +
- +#define ElementsInArray(x) (sizeof(x) / sizeof((x)[0]))
- + /*
- + * sets all categories - right now our poor man's emulation
- + * can't do it better
- + */
- + for(int i=0 ; i < ElementsInArray(newlocobj->locinfo->lc_category) ; i++) {
- + const char *curr_ln = newlocobj->locinfo->lc_category[1].locale;
- +#if 0
- + (void)fprintf(stderr,
- + "uselocale: switching to locale %d/|%s|\n",
- + i, curr_ln);
- +#endif
- + (void)setlocale(i, curr_ln);
- + }
- +
- + /* return the old locale_t */
- + return old_locale;
- +}
- +
- +void freelocale(locale_t locobj)
- +{
- + _free_locale(locobj);
- +}
- +#endif /* EMULATE_POSIX_NEWLOCALE_ON_WINDOWS */
- +
- +
- +
- +#ifdef CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L
- +/* cursed glibc does not provide |printf_l()| */
- +int vprintf_l(locale_t loc, const char *format, va_list ap)
- +{
- + locale_t prev_loc;
- + int ret;
- + int saved_errno;
- +
- + prev_loc = uselocale(loc);
- +
- + ret = vprintf(format, ap);
- + saved_errno = errno;
- +
- + (void)uselocale(prev_loc);
- +
- + errno = saved_errno;
- + return ret;
- +}
- +
- +int printf_l(locale_t loc, const char *format, ...)
- +{
- + va_list args;
- + int res;
- +
- + va_start(args, format);
- + res = vprintf_l(loc, format, args);
- + va_end(args);
- +
- + return res;
- +}
- +#endif /* CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L */
- +
- +} /* extern "C" */
- diff --git a/Base/RovLocale.hpp b/Base/RovLocale.hpp
- new file mode 100644
- index 0000000..ab4136e
- --- /dev/null
- +++ b/Base/RovLocale.hpp
- @@ -0,0 +1,60 @@
- +///////////////////////////////////////////////////////////////////////////////
- +// RovLocale.hpp POSIX i18n/l10n support functions
- +// Copyright ROVEMA
- +// Response Roland Mainz <roland.mainz@rovema.de>
- +// Description Support functions for i18n and l10n
- +///////////////////////////////////////////////////////////////////////////////
- +
- +#ifndef INC_ROVLOCALE_HPP
- +#define INC_ROVLOCALE_HPP 1
- +
- +extern "C" {
- +
- +#include <locale.h>
- +
- +#if defined(WIN32) && !defined(LC_GLOBAL_LOCATE)
- +#define EMULATE_POSIX_NEWLOCALE_ON_WINDOWS 1
- +#define CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L 1
- +#endif /* defined(WIN32) && !defined(LC_GLOBAL_LOCATE) */
- +
- +#ifdef __GLIBC__
- +/* { BSD, MacOSX, Illumos, ... } do not need this! */
- +#define CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L 1
- +#endif
- +
- +
- +/*
- + * POSIX |()*_l| functions, for platforms which do not implement them
- + */
- +#if CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L
- +#include <stdarg.h>
- +#include <errno.h>
- +
- +int vprintf_l(locale_t loc, const char *format, va_list ap);
- +int printf_l(locale_t loc, const char *format, ...);
- +#endif /* CURSED_GLIBC_DOES_NOT_HAVE_PRINTF_L */
- +
- +
- +/*
- + * POSIX |newlocale()|&co emulation for Windows
- + */
- +#if EMULATE_POSIX_NEWLOCALE_ON_WINDOWS
- +typedef _locale_t locale_t;
- +#define LC_ALL_MASK (LC_ALL)
- +
- +#define strtod_l(a, b, c) _strtod_l((a), (b), (c))
- +
- +locale_t newlocale(int mask, const char * locale, locale_t base_not_implemented);
- +locale_t uselocale(locale_t newlocobj);
- +void freelocale(locale_t locobj);
- +#endif /* EMULATE_POSIX_NEWLOCALE_ON_WINDOWS */
- +
- +
- +/*
- + * ROVEMA prototypes
- + */
- +extern locale_t rov_get_posix_localeobj(void);
- +
- +} /* extern "C" */
- +
- +#endif /* !INC_ROVLOCALE_HPP */
- diff --git a/Base/Win32System.hpp b/Base/Win32System.hpp
- index 17dac42..ec6b835 100755
- --- a/Base/Win32System.hpp
- +++ b/Base/Win32System.hpp
- @@ -22,6 +22,7 @@
- #include "RovTypes.hpp"
- #include "time.h"
- #include "Error.hpp"
- +#include "RovLocale.hpp"
- //-DEFINES/MACROS--------------------------------------------------------------
- //#ifdef WIN32
RDS: Windows locale fixes
Posted by Anonymous on Tue 27th Jun 2023 11:31
raw | new post
view followups (newest first): RDS: Windows locale fixes by Anonymous
modification of post by Anonymous (view diff)
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.