[MPlayer-cvslog] r29332 - in trunk: mp_msg.c osdep/getch2-os2.c osdep/getch2-win.c osdep/getch2.c
reimar
subversion at mplayerhq.hu
Sun May 31 15:00:51 CEST 2009
Author: reimar
Date: Sun May 31 15:00:51 2009
New Revision: 29332
Log:
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.
Modified:
trunk/mp_msg.c
trunk/osdep/getch2-os2.c
trunk/osdep/getch2-win.c
trunk/osdep/getch2.c
Modified: trunk/mp_msg.c
==============================================================================
--- trunk/mp_msg.c Sun May 31 14:48:53 2009 (r29331)
+++ trunk/mp_msg.c Sun May 31 15:00:51 2009 (r29332)
@@ -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
Modified: trunk/osdep/getch2-os2.c
==============================================================================
--- trunk/osdep/getch2-os2.c Sun May 31 14:48:53 2009 (r29331)
+++ trunk/osdep/getch2-os2.c Sun May 31 15:00:51 2009 (r29332)
@@ -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
Modified: trunk/osdep/getch2-win.c
==============================================================================
--- trunk/osdep/getch2-win.c Sun May 31 14:48:53 2009 (r29331)
+++ trunk/osdep/getch2-win.c Sun May 31 15:00:51 2009 (r29332)
@@ -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
Modified: trunk/osdep/getch2.c
==============================================================================
--- trunk/osdep/getch2.c Sun May 31 14:48:53 2009 (r29331)
+++ trunk/osdep/getch2.c Sun May 31 15:00:51 2009 (r29332)
@@ -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;
More information about the MPlayer-cvslog
mailing list