Skip to content

Commit 7bb36ce

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. Assisted-by: Sebastian Schuberth <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 894e323 commit 7bb36ce

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

winsup/cygwin/uinfo.cc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,43 @@ 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 = getenv("HOME");
2444+
if (!env)
2445+
{
2446+
char *drive = getenv("HOMEDRIVE"), *path = getenv("HOMEPATH");
2447+
if (drive && path)
2448+
{
2449+
int drive_len = strlen(drive), path_len = strlen(path);
2450+
home = (char *)malloc(drive_len + path_len + 1);
2451+
strcpy(home, drive);
2452+
strcpy(home + drive_len, path);
2453+
}
2454+
}
2455+
if (!env)
2456+
env = getenv("USERPROFILE");
2457+
2458+
if (env)
2459+
home = strdup(env);
2460+
2461+
/* Poor man's win32 -> POSIX conversion */
2462+
// is not available on 64-bit: cygwin_conv_to_posix_path(env, home);
2463+
if (home)
2464+
{
2465+
int i;
2466+
2467+
if (isalpha(home[0]) && home[1] == ':')
2468+
{
2469+
home[1] = home[0];
2470+
home[0] = '/';
2471+
}
2472+
for (i = 0; home[i]; i++)
2473+
if (home[i] == '\\')
2474+
home[i] = '/';
2475+
}
2476+
}
2477+
24412478
if (is_group ())
24422479
__small_sprintf (linebuf, "%W:%s:%u:",
24432480
posix_name, sid.string ((char *) sidstr), uid);

0 commit comments

Comments
 (0)