[vlc-devel] [PATCH] [RFC] vlc_fixups.h: add a uselocale implementation for win32
Adrien Maglo
magsoft at videolan.org
Fri Dec 15 17:31:34 CET 2017
This implementation comes from libcxx.
---
include/vlc_fixups.h | 46 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 42 insertions(+), 4 deletions(-)
diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h
index 6175a539bd..c45294d19e 100644
--- a/include/vlc_fixups.h
+++ b/include/vlc_fixups.h
@@ -320,10 +320,47 @@ void *aligned_alloc(size_t, size_t);
/* locale.h */
#ifndef HAVE_USELOCALE
-#define LC_ALL_MASK 0
-#define LC_NUMERIC_MASK 0
-#define LC_MESSAGES_MASK 0
-#define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
+# if defined(_WIN32)
+# include <xlocinfo.h> // _locale_t
+# undef _UP // It conflicts with unique_ptr.h on MinGW...
+# define locale_t _locale_t
+# define LC_COLLATE_MASK _M_COLLATE
+# define LC_CTYPE_MASK _M_CTYPE
+# define LC_MONETARY_MASK _M_MONETARY
+# define LC_NUMERIC_MASK _M_NUMERIC
+# define LC_TIME_MASK _M_TIME
+# define LC_MESSAGES_MASK _M_MESSAGES
+# define LC_ALL_MASK ( LC_COLLATE_MASK \
+ | LC_CTYPE_MASK \
+ | LC_MESSAGES_MASK \
+ | LC_MONETARY_MASK \
+ | LC_NUMERIC_MASK \
+ | LC_TIME_MASK )
+# define freelocale _free_locale
+
+// Base is not used...
+static inline locale_t newlocale( int mask, const char * locale, locale_t base )
+{
+ (void)base;
+ return _create_locale( mask, locale );
+}
+
+static inline locale_t uselocale( locale_t newloc )
+{
+ locale_t old_locale = _get_current_locale();
+ // uselocale sets the thread's locale by definition, so unconditionally use thread-local locale
+ _configthreadlocale( _ENABLE_PER_THREAD_LOCALE );
+ // uselocale sets all categories
+ setlocale( LC_ALL, newloc->locinfo->lc_category[LC_ALL].locale );
+ // uselocale returns the old locale_t
+ return old_locale;
+}
+
+# else
+# define LC_ALL_MASK 0
+# define LC_NUMERIC_MASK 0
+# define LC_MESSAGES_MASK 0
+# define LC_GLOBAL_LOCALE ((locale_t)(uintptr_t)1)
typedef void *locale_t;
static inline locale_t uselocale(locale_t loc)
{
@@ -339,6 +376,7 @@ static inline locale_t newlocale(int mask, const char * locale, locale_t base)
(void)mask; (void)locale; (void)base;
return NULL;
}
+# endif
#endif
#if !defined (HAVE_STATIC_ASSERT) && !defined(__cpp_static_assert)
--
2.14.1
More information about the vlc-devel
mailing list