diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-08-29 22:08:53 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-08-29 22:08:53 +0200 |
commit | 48340b62e812dc9280f621a2eb6db76d43555c66 (patch) | |
tree | cdafeefc8f1ac57190fcd2b97f717c84fdd6b658 /src/misc1.c | |
parent | 97f65fafdbf3530fa42d6e43618e66e14c866b50 (diff) | |
download | vim-git-48340b62e812dc9280f621a2eb6db76d43555c66.tar.gz |
patch 8.0.1012: MS-Windows: problem with $HOME when is was set internallyv8.0.1012
Problem: MS-Windows: Problem with $HOME when is was set internally.
Solution: Only use the $HOME default internally. (Yasuhiro Matsumoto, closes
#2013)
Diffstat (limited to 'src/misc1.c')
-rw-r--r-- | src/misc1.c | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/src/misc1.c b/src/misc1.c index bd7dcefbe..632571dbe 100644 --- 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 (var != NULL && *var == NUL) /* empty is same as not set */ + var = NULL; -# if defined(FEAT_MBYTE) +# 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; |