[vlc-commits] commit: nl_langinfo is not thread-safe, avoid it ( Rémi Denis-Courmont )

git at videolan.org git at videolan.org
Sun Jul 18 11:18:18 CEST 2010


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 18 11:59:57 2010 +0300| [9164192f0231bed4913e5cd3bb4174343163439b] | committer: Rémi Denis-Courmont 

nl_langinfo is not thread-safe, avoid it

This brings some useless overhead for native UTF-8 systems.
Linux packagers may want to define ASSUME_UTF8 to avoid this problem.

Also, this assumes that iconv_open() recognizes "" as the current
character set (POSIX says nothing about valid iconv_open() parameters).

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=9164192f0231bed4913e5cd3bb4174343163439b
---

 src/text/unicode.c |   33 +++------------------------------
 1 files changed, 3 insertions(+), 30 deletions(-)

diff --git a/src/text/unicode.c b/src/text/unicode.c
index 77b7684..41734ed 100644
--- a/src/text/unicode.c
+++ b/src/text/unicode.c
@@ -57,38 +57,14 @@
 # error No UTF8 charset conversion implemented on this platform!
 #endif
 
-#if defined (USE_ICONV)
-# include <langinfo.h>
-static char charset[sizeof ("CSISO11SWEDISHFORNAMES")] = "";
-
-static void find_charset_once (void)
-{
-    strlcpy (charset, nl_langinfo (CODESET), sizeof (charset));
-    if (!strcasecmp (charset, "ASCII")
-     || !strcasecmp (charset, "ANSI_X3.4-1968"))
-        strcpy (charset, "UTF-8"); /* superset... */
-}
-
-static int find_charset (void)
-{
-    static pthread_once_t once = PTHREAD_ONCE_INIT;
-    pthread_once (&once, find_charset_once);
-    return !strcasecmp (charset, "UTF-8");
-}
-#endif
-
-
 static char *locale_fast (const char *string, bool from)
 {
     if( string == NULL )
         return NULL;
 
 #if defined (USE_ICONV)
-    if (find_charset ())
-        return (char *)string;
-
-    vlc_iconv_t hd = vlc_iconv_open (from ? "UTF-8" : charset,
-                                     from ? charset : "UTF-8");
+    vlc_iconv_t hd = vlc_iconv_open (from ? "UTF-8" : "",
+                                     from ? "" : "UTF-8");
     if (hd == (vlc_iconv_t)(-1))
         return NULL; /* Uho! */
 
@@ -144,8 +120,6 @@ static inline char *locale_dup (const char *string, bool from)
     assert( string );
 
 #if defined (USE_ICONV)
-    if (find_charset ())
-        return strdup (string);
     return locale_fast (string, from);
 #elif defined (USE_MB2MB)
     return locale_fast (string, from);
@@ -162,8 +136,7 @@ static inline char *locale_dup (const char *string, bool from)
 void LocaleFree (const char *str)
 {
 #if defined (USE_ICONV)
-    if (!find_charset ())
-        free ((char *)str);
+    free ((char *)str);
 #elif defined (USE_MB2MB)
     free ((char *)str);
 #else



More information about the vlc-commits mailing list