Skip to content

Commit fc613d2

Browse files
committed
Merge branch 'kb/mingw-set-home'
Windows port update. * kb/mingw-set-home: mingw: initialize HOME on startup
2 parents dd0bc5b + e12a955 commit fc613d2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

compat/mingw.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,30 @@ static void setup_windows_environment(void)
23332333
/* simulate TERM to enable auto-color (see color.c) */
23342334
if (!getenv("TERM"))
23352335
setenv("TERM", "cygwin", 1);
2336+
2337+
/* calculate HOME if not set */
2338+
if (!getenv("HOME")) {
2339+
/*
2340+
* try $HOMEDRIVE$HOMEPATH - the home share may be a network
2341+
* location, thus also check if the path exists (i.e. is not
2342+
* disconnected)
2343+
*/
2344+
if ((tmp = getenv("HOMEDRIVE"))) {
2345+
struct strbuf buf = STRBUF_INIT;
2346+
strbuf_addstr(&buf, tmp);
2347+
if ((tmp = getenv("HOMEPATH"))) {
2348+
strbuf_addstr(&buf, tmp);
2349+
if (is_directory(buf.buf))
2350+
setenv("HOME", buf.buf, 1);
2351+
else
2352+
tmp = NULL; /* use $USERPROFILE */
2353+
}
2354+
strbuf_release(&buf);
2355+
}
2356+
/* use $USERPROFILE if the home share is not available */
2357+
if (!tmp && (tmp = getenv("USERPROFILE")))
2358+
setenv("HOME", tmp, 1);
2359+
}
23362360
}
23372361

23382362
#if !defined(_MSC_VER)

0 commit comments

Comments
 (0)