diff options
author | Arnavion <arnavion@gmail.com> | 2014-04-21 08:08:18 -0700 |
---|---|---|
committer | Arnavion <arnavion@gmail.com> | 2014-04-21 09:16:13 -0700 |
commit | e4413e017888b733e00b4e74e6b459c611a8246a (patch) | |
tree | 69b538fd4c11db3c0b5a1460f4d44ae05d2f2bdc /src/common | |
parent | dc27640265dcbe480ad137831f3a22f35bd07b51 (diff) |
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.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/cfgfiles.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/common/cfgfiles.c b/src/common/cfgfiles.c index 59761bc5..7f6bc3ed 100644 --- a/src/common/cfgfiles.c +++ b/src/common/cfgfiles.c @@ -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); - } + utf = g_strdup (fallback); +#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"); |