Don't convert the result of g_get_user_name / g_get_real_name from locale to utf-8 on Windows. They return utf-8 already.

This commit is contained in:
Arnavion 2014-04-21 08:08:18 -07:00
parent dc27640265
commit e4413e0178
1 changed files with 14 additions and 11 deletions

View File

@ -613,16 +613,19 @@ convert_with_fallback (const char *str, const char *fallback)
{
char *utf;
utf = g_locale_to_utf8 (str, -1, 0, 0, 0);
#ifndef WIN32
/* On non-Windows, g_get_user_name and g_get_real_name return a string in system locale, so convert it to utf-8. */
utf = g_locale_to_utf8 (str, -1, NULL, NULL, 0);
g_free (str);
/* The returned string is NULL if conversion from locale to utf-8 failed for any reason. Return the fallback. */
if (!utf)
{
/* this can happen if CHARSET envvar is set wrong */
/* maybe it's already utf8 (breakage!) */
if (!g_utf8_validate (str, -1, NULL))
utf = g_strdup (fallback);
else
utf = g_strdup (str);
}
#else
/* On Windows, they return a string in utf-8, so don't do anything to it. The fallback isn't needed. */
utf = str;
#endif
return utf;
}
@ -739,13 +742,13 @@ load_default_config(void)
username = g_get_user_name ();
if (!username)
username = "root";
username = g_strdup ("root");
/* We hid Real name from the Network List, so don't use the user's name unnoticeably */
/* realname = g_get_real_name ();
if ((realname && realname[0] == 0) || !realname)
realname = username; */
realname = "realname";
realname = g_strdup ("realname");
username = convert_with_fallback (username, "username");
realname = convert_with_fallback (realname, "realname");