summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2012-02-04 23:05:42 +0000
committerSimon Howard2012-02-04 23:05:42 +0000
commit920ffea9b631e712ff0826911db01a76edbe7521 (patch)
treef4fef93bde165c650a3a61ac8cee4a90876d7df1 /src
parentc6b8f1163708db85251daac24b2ffa6bea24a72a (diff)
downloadchocolate-doom-920ffea9b631e712ff0826911db01a76edbe7521.tar.gz
chocolate-doom-920ffea9b631e712ff0826911db01a76edbe7521.tar.bz2
chocolate-doom-920ffea9b631e712ff0826911db01a76edbe7521.zip
On Windows, convert the USER and USERNAME environment variables from OEM
codepage to UTF-8 encoding. This should fix the case where the user has a username that includes non-ASCII characters (thanks Alexandre Xavier). Subversion-branch: /trunk/chocolate-doom Subversion-revision: 2495
Diffstat (limited to 'src')
-rw-r--r--src/m_misc.c23
-rw-r--r--src/m_misc.h1
-rw-r--r--src/net_client.c12
3 files changed, 34 insertions, 2 deletions
diff --git a/src/m_misc.c b/src/m_misc.c
index 9a5fb84a..31c87898 100644
--- a/src/m_misc.c
+++ b/src/m_misc.c
@@ -30,9 +30,9 @@
#include <ctype.h>
#include <errno.h>
-// for mkdir:
-
#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
#include <io.h>
#ifdef _MSC_VER
#include <direct.h>
@@ -206,3 +206,22 @@ boolean M_StrToInt(const char *str, int *result)
|| sscanf(str, " %d", result) == 1;
}
+#ifdef _WIN32
+
+char *M_OEMToUTF8(const char *oem)
+{
+ unsigned int len = strlen(oem) + 1;
+ wchar_t *tmp;
+ char *result;
+
+ tmp = malloc(len * sizeof(wchar_t));
+ MultiByteToWideChar(CP_OEMCP, 0, oem, len, tmp, len);
+ result = malloc(len * 4);
+ WideCharToMultiByte(CP_UTF8, 0, tmp, len, result, len * 4, NULL, NULL);
+ free(tmp);
+
+ return result;
+}
+
+#endif
+
diff --git a/src/m_misc.h b/src/m_misc.h
index 0fe8e62e..6c2da4b1 100644
--- a/src/m_misc.h
+++ b/src/m_misc.h
@@ -40,6 +40,7 @@ char *M_TempFile(char *s);
boolean M_FileExists(char *file);
long M_FileLength(FILE *handle);
boolean M_StrToInt(const char *str, int *result);
+char *M_OEMToUTF8(const char *ansi);
#endif
diff --git a/src/net_client.c b/src/net_client.c
index e338362e..b3109ecd 100644
--- a/src/net_client.c
+++ b/src/net_client.c
@@ -33,6 +33,7 @@
#include "i_system.h"
#include "i_timer.h"
#include "m_argv.h"
+#include "m_misc.h"
#include "net_client.h"
#include "net_common.h"
#include "net_defs.h"
@@ -1273,6 +1274,17 @@ void NET_CL_Init(void)
net_player_name = getenv("USER");
if (net_player_name == NULL)
net_player_name = getenv("USERNAME");
+
+ // On Windows, environment variables are in OEM codepage
+ // encoding, so convert to UTF8:
+
+#ifdef _WIN32
+ if (net_player_name != NULL)
+ {
+ net_player_name = M_OEMToUTF8(net_player_name);
+ }
+#endif
+
if (net_player_name == NULL)
net_player_name = "Player";
}