From 83cc55c7f7c03e7deb1476ee7aac13946970e561 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Denis-Courmont?= <rem@videolan.org> Date: Sun, 14 May 2006 13:04:48 +0000 Subject: [PATCH] Some users reported problems with subtitles encoding on Win32. Probably a setlocale() breakage. Use GetACP() instead. --- src/misc/charset.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/misc/charset.c b/src/misc/charset.c index 58147cca1efe..e5a1746cfa00 100644 --- a/src/misc/charset.c +++ b/src/misc/charset.c @@ -283,7 +283,7 @@ vlc_bool_t vlc_current_charset( char **psz_charset ) char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ - sprintf( buf, "CP%u", GetACP() ); + snprintf( buf, sizeof( buf ), "CP%u", GetACP() ); psz_codeset = buf; #elif defined OS2 @@ -312,7 +312,7 @@ vlc_bool_t vlc_current_charset( char **psz_charset ) psz_codeset = ""; else { - sprintf( buf, "CP%u", cp[0] ); + snprintf( buf, sizeof( buf ), "CP%u", cp[0] ); psz_codeset = buf; } } @@ -564,11 +564,12 @@ const char *FindFallbackEncoding( const char *locale ) */ const char *GetFallbackEncoding( void ) { +#ifndef WIN32 const char *psz_lang = NULL; /* Some systems (like Darwin, SunOS 4 or DJGPP) have only the C locale. * Therefore we don't use setlocale here; it would return "C". */ -# if HAVE_SETLOCALE && !__APPLE__ +# if defined (HAVE_SETLOCALE) && !defined ( __APPLE__) psz_lang = setlocale( LC_ALL, NULL ); # endif if( psz_lang == NULL || psz_lang[0] == '\0' ) @@ -583,6 +584,17 @@ const char *GetFallbackEncoding( void ) } return FindFallbackEncoding( psz_lang ); +#else + /* + * This should be thread-safe given GetACP() should always return + * the same result. + */ + static char buf[2 + 10 + 1] = ""; + + if( buf[0] == 0 ) + snprintf( buf, sizeof( buf ), "CP%u", GetACP() ); + return buf; +#endif } /** -- GitLab