emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master 753c565: Upcase Path and ComSpec in process-environ


From: Noam Postavsky
Subject: [Emacs-diffs] master 753c565: Upcase Path and ComSpec in process-environment
Date: Mon, 28 Nov 2016 22:45:02 +0000 (UTC)

branch: master
commit 753c565df6aa693c75c38816059051a1aebbcbb1
Author: Noam Postavsky <address@hidden>
Commit: Noam Postavsky <address@hidden>

    Upcase Path and ComSpec in process-environment
    
    Since 2016-07-18 "Keep w32 environment settings internal only", the
    upcasing of environment variables "Path" and "ComSpec" occured after
    initializing process-environment.  This meant that Lisp code trying to
    override "PATH" environment had no effect (Bug #24956).
    
    * src/w32.c (init_environment): Upcase the "Path" and "ComSpec" entries
    in Vprocess_environment.
---
 src/w32.c |   25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/w32.c b/src/w32.c
index ad7d94a..086c1ac 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -2863,12 +2863,29 @@ init_environment (char ** argv)
      The same applies to COMSPEC.  */
   {
     char ** envp;
+    const char *path = "PATH=";
+    int path_len = strlen (path);
+    const char *comspec = "COMSPEC=";
+    int comspec_len = strlen (comspec);
 
     for (envp = environ; *envp; envp++)
-      if (_strnicmp (*envp, "PATH=", 5) == 0)
-       memcpy (*envp, "PATH=", 5);
-      else if (_strnicmp (*envp, "COMSPEC=", 8) == 0)
-       memcpy (*envp, "COMSPEC=", 8);
+      if (_strnicmp (*envp, path, path_len) == 0)
+        memcpy (*envp, path, path_len);
+      else if (_strnicmp (*envp, comspec, comspec_len) == 0)
+        memcpy (*envp, comspec, comspec_len);
+
+    /* Make the same modification to `process-environment' which has
+       already been initialized in set_initial_environment.  */
+    for (Lisp_Object env = Vprocess_environment; CONSP (env); env = XCDR (env))
+    {
+      Lisp_Object entry = XCAR (env);
+      if (_strnicmp (SDATA (entry), path, path_len) == 0)
+        for (int i = 0; i < path_len; i++)
+          SSET (entry, i, path[i]);
+      else if (_strnicmp (SDATA (entry), comspec, comspec_len) == 0)
+        for (int i = 0; i < comspec_len; i++)
+          SSET (entry, i, comspec[i]);
+    }
   }
 
   /* Remember the initial working directory for getcwd.  */



reply via email to

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