vlc_bool_t vlc_current_charset( char **psz_charset ) { const char *psz_codeset; #if !(defined WIN32 || defined OS2) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo( CODESET ) nowadays. */ psz_codeset = nl_langinfo( CODESET ); # else /* On old systems which lack it, use setlocale or getenv. */ const char *psz_locale = NULL; /* But most old systems don't have a complete set of locales. Some * (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't * use setlocale here; it would return "C" when it doesn't support the * locale name the user has set. Darwin's setlocale is broken. */ # if HAVE_SETLOCALE && !SYS_DARWIN psz_locale = setlocale( LC_ALL, NULL ); # endif if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || psz_locale[0] == '\0') psz_locale = getenv( "LANG" ); } } /* On some old systems, one used to set locale = "iso8859_1". On others, * you set it to "language_COUNTRY.charset". Darwin only has LANG :( */ psz_codeset = vlc_encoding_from_locale( (char *)psz_locale ); # endif /* HAVE_LANGINFO_CODESET */ #elif defined WIN32 static char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ sprintf( buf, "CP%u", GetACP() ); psz_codeset = buf; #elif defined OS2 const char *psz_locale; static char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, * with standard language environment variables. */ psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz+locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || locale[0] == '\0' ) locale = getenv( "LANG" ); } if( psz_locale != NULL && psz_locale[0] != '\0' ) psz_codeset = vlc_encoding_from_locale( psz_locale ); else { /* OS/2 has a function returning the locale's codepage as a number. */ if( DosQueryCp( sizeof( cp ), cp, &cplen ) ) psz_codeset = ""; else { sprintf( buf, "CP%u", cp[0] ); psz_codeset = buf; } } #endif if( psz_codeset == NULL ) /* The canonical name cannot be determined. */ psz_codeset = ""; else psz_codeset = vlc_charset_aliases( psz_codeset ); /* Don't return an empty string. GNU libc and GNU libiconv interpret * the empty string as denoting "the locale's character encoding", * thus GNU libiconv would call this function a second time. */ if( psz_codeset[0] == '\0' ) { /* Last possibility is 'CHARSET' enviroment variable */ if( !( psz_codeset = getenv( "CHARSET" ) ) ) psz_codeset = "ISO-8859-1"; } if( psz_charset ) *psz_charset = strdup((char *)psz_codeset); if( !strcasecmp(psz_codeset, "UTF8") || !strcasecmp(psz_codeset, "UTF-8") ) return VLC_TRUE; return VLC_FALSE; }
vlc_bool_t vlc_current_charset( char **psz_charset ) { const char *psz_codeset; #if !(defined WIN32 || defined OS2 || defined __APPLE__) # if HAVE_LANGINFO_CODESET /* Most systems support nl_langinfo( CODESET ) nowadays. */ psz_codeset = nl_langinfo( CODESET ); if( !strcmp( psz_codeset, "ANSI_X3.4-1968" ) ) psz_codeset = "ASCII"; # else /* On old systems which lack it, use setlocale or getenv. */ const char *psz_locale = NULL; char buf[2 + 10 + 1]; /* But most old systems don't have a complete set of locales. Some * (like SunOS 4 or DJGPP) have only the C locale. Therefore we don't * use setlocale here; it would return "C" when it doesn't support the * locale name the user has set. Darwin's setlocale is broken. */ # if HAVE_SETLOCALE && !__APPLE__ psz_locale = setlocale( LC_ALL, NULL ); # endif if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz_locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || psz_locale[0] == '\0') psz_locale = getenv( "LANG" ); } } /* On some old systems, one used to set locale = "iso8859_1". On others, * you set it to "language_COUNTRY.charset". Darwin only has LANG :( */ vlc_encoding_from_locale( (char *)psz_locale, buf ); psz_codeset = buf; # endif /* HAVE_LANGINFO_CODESET */ #elif defined __APPLE__ /* Darwin is always using UTF-8 internally. */ psz_codeset = "UTF-8"; #elif defined WIN32 char buf[2 + 10 + 1]; /* Woe32 has a function returning the locale's codepage as a number. */ snprintf( buf, sizeof( buf ), "CP%u", GetACP() ); psz_codeset = buf; #elif defined OS2 const char *psz_locale; char buf[2 + 10 + 1]; ULONG cp[3]; ULONG cplen; /* Allow user to override the codeset, as set in the operating system, * with standard language environment variables. */ psz_locale = getenv( "LC_ALL" ); if( psz_locale == NULL || psz_locale[0] == '\0' ) { psz+locale = getenv( "LC_CTYPE" ); if( psz_locale == NULL || locale[0] == '\0' ) locale = getenv( "LANG" ); } if( psz_locale != NULL && psz_locale[0] != '\0' ) vlc_encoding_from_locale( psz_locale, buf ); psz_codeset = buf; else { /* OS/2 has a function returning the locale's codepage as a number. */ if( DosQueryCp( sizeof( cp ), cp, &cplen ) )