Commit 4d00262a authored by Eli Zaretskii's avatar Eli Zaretskii

Support ~USER for some names on MS-Windows

* src/w32.c (getpwnam): Support usernames provided through
LOGNAME or USERNAME environment variables, to mimic what
editfns.c:init_editfns does.
parent c3f87efe
Pipeline #775 failed with stage
in 51 minutes and 49 seconds
......@@ -2091,7 +2091,29 @@ getpwnam (char *name)
return pw;
if (xstrcasecmp (name, pw->pw_name))
return NULL;
{
/* Mimic what init_editfns does with these environment
variables, so that the likes of ~USER is recognized by
expand-file-name even if $LOGNAME gives a name different from
the real username produced by the process token. */
char *logname = getenv ("LOGNAME");
char *username = getenv ("USERNAME");
if ((logname || username)
&& xstrcasecmp (name, logname ? logname : username) == 0)
{
static struct passwd alias_user;
static char alias_name[PASSWD_FIELD_SIZE];
memcpy (&alias_user, &dflt_passwd, sizeof dflt_passwd);
alias_name[0] = '\0';
strncat (alias_name, logname ? logname : username,
PASSWD_FIELD_SIZE - 1);
alias_user.pw_name = alias_name;
pw = &alias_user;
}
else
return NULL;
}
return pw;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment