Skip to content

Commit bee83c5

Browse files
committed
Fall back to HOME environment variable
So far, MSys2 always insists on using /home/<username> as home directory, even when the HOME variable is set. For consistency, let's adopt Git for Windows' strategy to look at the HOME variable, falling back to $HOMEDRIVE$HOMEPAT, and falling back even further to $USERPROFILE. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 894e323 commit bee83c5

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

winsup/cygwin/uinfo.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,45 @@ pwdgrp::fetch_account_from_windows (fetch_user_arg_t &arg, cyg_ldap *pldap)
24382438
p = wcpcpy (wcpcpy (p, dom), cygheap->pg.nss_separator ());
24392439
wcpcpy (p, name);
24402440

2441+
if (!home)
2442+
{
2443+
char *env = NULL;
2444+
env = getenv("HOME");
2445+
if (!env)
2446+
{
2447+
char *drive = getenv("HOMEDRIVE"), *path = getenv("HOMEPATH");
2448+
if (drive && path)
2449+
{
2450+
int drive_len = strlen(drive), path_len = strlen(path);
2451+
home = (char *)malloc(drive_len + path_len + 1);
2452+
memcpy(home, drive, drive_len);
2453+
memcpy(home + drive_len, path, path_len);
2454+
home[drive_len + path_len] = '\0';
2455+
}
2456+
}
2457+
if (!env)
2458+
env = getenv("USERPROFILE");
2459+
2460+
if (env)
2461+
home = strdup(env);
2462+
2463+
/* Poor man's win32 -> POSIX conversion */
2464+
// is not available on 64-bit: cygwin_conv_to_posix_path(env, home);
2465+
if (home)
2466+
{
2467+
int i;
2468+
2469+
if (isalpha(home[0]) && home[1] == ':')
2470+
{
2471+
home[1] = home[0];
2472+
home[0] = '/';
2473+
}
2474+
for (i = 0; home[i]; i++)
2475+
if (home[i] == '\\')
2476+
home[i] = '/';
2477+
}
2478+
}
2479+
24412480
if (is_group ())
24422481
__small_sprintf (linebuf, "%W:%s:%u:",
24432482
posix_name, sid.string ((char *) sidstr), uid);

0 commit comments

Comments
 (0)