emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 4d00262: Support ~USER for some names on MS-Windows


From: Eli Zaretskii
Subject: [Emacs-diffs] master 4d00262: Support ~USER for some names on MS-Windows
Date: Fri, 15 Feb 2019 05:23:36 -0500 (EST)

branch: master
commit 4d00262a8ebd3c8a0f3679a710b6bb8657bf2ca1
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    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.
---
 src/w32.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)

diff --git a/src/w32.c b/src/w32.c
index c75a4f9..197f6dd 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -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;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]