From 4a5a17507fe1e12ee02c174350edc479fb01ac01 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 13 Nov 2018 22:01:57 +0200 Subject: [PATCH] Fix recent change in fileio.c * src/fileio.c (get_homedir) [WINDOWSNT]: Convert $HOME to UTF-8. (Fexpand_file_name): Don't convert it here. --- src/fileio.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index e178c39fc18..59446ac1833 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -1096,18 +1096,7 @@ the root directory. */) newdir = get_homedir (); nm++; -#ifdef WINDOWSNT - if (newdir[0]) - { - char newdir_utf8[MAX_UTF8_PATH]; - - filename_from_ansi (newdir, newdir_utf8); - tem = make_unibyte_string (newdir_utf8, strlen (newdir_utf8)); - newdir = SSDATA (tem); - } - else -#endif - tem = build_string (newdir); + tem = build_string (newdir); newdirlim = newdir + SBYTES (tem); /* get_homedir may return a unibyte string, which will bite us if we expect the directory to be multibyte. */ @@ -1669,6 +1658,19 @@ char const * get_homedir (void) { char const *home = egetenv ("HOME"); + +#ifdef WINDOWSNT + /* getpw* functions return UTF-8 encoded file names, whereas egetenv + returns strings in locale encoding, so we need to convert for + consistency. */ + char homedir_utf8[MAX_UTF8_PATH]; + if (home) + { + filename_from_ansi (home, homedir_utf8); + home = homedir_utf8; + } +#endif + if (!home) { static char const *userenv[] = {"LOGNAME", "USER"}; -- 2.39.2