Mercurial > vim
diff src/misc1.c @ 12265:03e4be2e3d53 v8.0.1012
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
commit https://github.com/vim/vim/commit/48340b62e812dc9280f621a2eb6db76d43555c66
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 29 22:08:53 2017 +0200
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internally
Problem: MS-Windows: Problem with $HOME when is was set internally.
Solution: Only use the $HOME default internally. (Yasuhiro Matsumoto, closes
#2013)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 29 Aug 2017 22:15:05 +0200 |
parents | 0066a7e178bc |
children | d2373927d76d |
line wrap: on
line diff
--- a/src/misc1.c +++ b/src/misc1.c @@ -3750,11 +3750,34 @@ init_homedir(void) var = mch_getenv((char_u *)"HOME"); #endif - if (var != NULL && *var == NUL) /* empty is same as not set */ - var = NULL; - #ifdef WIN3264 /* + * Typically, $HOME is not defined on Windows, unless the user has + * specifically defined it for Vim's sake. However, on Windows NT + * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for + * each user. Try constructing $HOME from these. + */ + if (var == NULL || *var == NULL) + { + char_u *homedrive, *homepath; + + homedrive = mch_getenv((char_u *)"HOMEDRIVE"); + homepath = mch_getenv((char_u *)"HOMEPATH"); + if (homepath == NULL || *homepath == NUL) + homepath = (char_u *)"\\"; + if (homedrive != NULL + && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL) + { + sprintf((char *)NameBuff, "%s%s", homedrive, homepath); + if (NameBuff[0] != NUL) + var = NameBuff; + } + } + + if (var == NULL) + var = mch_getenv((char_u *)"USERPROFILE"); + + /* * Weird but true: $HOME may contain an indirect reference to another * variable, esp. "%USERPROFILE%". Happens when $USERPROFILE isn't set * when $HOME is being set. @@ -3774,40 +3797,14 @@ init_homedir(void) { vim_snprintf((char *)NameBuff, MAXPATHL, "%s%s", exp, p + 1); var = NameBuff; - /* Also set $HOME, it's needed for _viminfo. */ - vim_setenv((char_u *)"HOME", NameBuff); - } - } - } - - /* - * Typically, $HOME is not defined on Windows, unless the user has - * specifically defined it for Vim's sake. However, on Windows NT - * platforms, $HOMEDRIVE and $HOMEPATH are automatically defined for - * each user. Try constructing $HOME from these. - */ - if (var == NULL) - { - char_u *homedrive, *homepath; - - homedrive = mch_getenv((char_u *)"HOMEDRIVE"); - homepath = mch_getenv((char_u *)"HOMEPATH"); - if (homepath == NULL || *homepath == NUL) - homepath = (char_u *)"\\"; - if (homedrive != NULL - && STRLEN(homedrive) + STRLEN(homepath) < MAXPATHL) - { - sprintf((char *)NameBuff, "%s%s", homedrive, homepath); - if (NameBuff[0] != NUL) - { - var = NameBuff; - /* Also set $HOME, it's needed for _viminfo. */ - vim_setenv((char_u *)"HOME", NameBuff); - } - } - } - -# if defined(FEAT_MBYTE) + } + } + } + + if (var != NULL && *var == NUL) /* empty is same as not set */ + var = NULL; + +# ifdef FEAT_MBYTE if (enc_utf8 && var != NULL) { int len; @@ -3823,9 +3820,7 @@ init_homedir(void) } } # endif -#endif - -#if defined(MSWIN) + /* * Default home dir is C:/ * Best assumption we can make in such a situation. @@ -3833,6 +3828,7 @@ init_homedir(void) if (var == NULL) var = (char_u *)"C:/"; #endif + if (var != NULL) { #ifdef UNIX @@ -4662,6 +4658,10 @@ home_replace( #else homedir_env_orig = homedir_env = mch_getenv((char_u *)"HOME"); #endif +#ifdef WIN3264 + if (homedir_env == NULL) + homedir_env_orig = homedir_env = mch_getenv((char_u *)"USERPROFILE"); +#endif /* Empty is the same as not set. */ if (homedir_env != NULL && *homedir_env == NUL) homedir_env = NULL;