mirror of
https://github.com/mpv-player/mpv
synced 2025-02-27 10:50:53 +00:00
Use a malloced string for the get_term_charset return value.
This is necessary at least on POSIX systems since the buffer returned by nl_langinfo may change its contents with e.g. each setlocale call. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29332 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
960285ea46
commit
71fefd86ac
7
mp_msg.c
7
mp_msg.c
@ -8,6 +8,13 @@
|
||||
#ifdef CONFIG_ICONV
|
||||
#include <iconv.h>
|
||||
#include <errno.h>
|
||||
/**
|
||||
* \brief gets the name of the system's terminal character set
|
||||
* \return a malloced string indicating the system charset
|
||||
*
|
||||
* Be warned that this function on many systems is in no way thread-safe
|
||||
* since it modifies global data
|
||||
*/
|
||||
char* get_term_charset(void);
|
||||
#endif
|
||||
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <os2.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "keycodes.h"
|
||||
@ -189,7 +190,7 @@ char *get_term_charset( void )
|
||||
|
||||
#ifdef HAVE_LANGINFO
|
||||
setlocale( LC_CTYPE, "");
|
||||
charset = nl_langinfo( CODESET );
|
||||
charset = strdup( nl_langinfo( CODESET ));
|
||||
setlocale( LC_CTYPE, "C");
|
||||
#endif
|
||||
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <windows.h>
|
||||
#include "keycodes.h"
|
||||
#include "input/input.h"
|
||||
@ -187,7 +188,7 @@ static const struct {
|
||||
|
||||
char* get_term_charset(void)
|
||||
{
|
||||
static char codepage[10];
|
||||
char codepage[10];
|
||||
unsigned i, cpno = GetConsoleOutputCP();
|
||||
if (!cpno)
|
||||
cpno = GetACP();
|
||||
@ -196,9 +197,9 @@ char* get_term_charset(void)
|
||||
|
||||
for (i = 0; cp_alias[i].cp; i++)
|
||||
if (cpno == cp_alias[i].cp)
|
||||
return cp_alias[i].alias;
|
||||
return strdup(cp_alias[i].alias);
|
||||
|
||||
snprintf(codepage, sizeof(codepage), "CP%u", cpno);
|
||||
return codepage;
|
||||
return strdup(codepage);
|
||||
}
|
||||
#endif
|
||||
|
@ -297,7 +297,7 @@ char* get_term_charset(void)
|
||||
char* charset = NULL;
|
||||
#ifdef HAVE_LANGINFO
|
||||
setlocale(LC_CTYPE, "");
|
||||
charset = nl_langinfo(CODESET);
|
||||
charset = strdup(nl_langinfo(CODESET));
|
||||
setlocale(LC_CTYPE, "C");
|
||||
#endif
|
||||
return charset;
|
||||
|
Loading…
Reference in New Issue
Block a user