emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] master e35708b: Support invoking Emacs via a symlink on MS


From: Eli Zaretskii
Subject: [Emacs-diffs] master e35708b: Support invoking Emacs via a symlink on MS-Windows
Date: Wed, 26 Jun 2019 12:24:50 -0400 (EDT)

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

    Support invoking Emacs via a symlink on MS-Windows
    
    * src/w32.c (w32_my_exename): Resolve symlinks in the
    executable name, to support searching for the pdumper file
    when the executable is found via a symlink.
    * src/emacs.c (load_pdump): Add a comment about symlink
    resolution on Windows.
---
 src/emacs.c |  2 ++
 src/w32.c   | 24 ++++++++++++++++++++----
 2 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/src/emacs.c b/src/emacs.c
index 231acc0..d5eccf7 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -868,6 +868,8 @@ load_pdump (int argc, char **argv)
   if (exename)
     {
 #ifdef WINDOWSNT
+      /* w32_my_exename resolves symlinks internally, so no need to
+        call realpath.  */
       real_exename = exename;
       exename = NULL;
 #else
diff --git a/src/w32.c b/src/w32.c
index b2d1ffc..36a5a37 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -9988,18 +9988,34 @@ w32_relocate (const char *epath_dir)
   return epath_dir;
 }
 
-/* Return the full absolute name of the running executable.
+/* Return the full absolute name of the running executable.  If the
+   executable is a symlink, resolve it.
 
    Note: this function is called early during startup, when Unicode
-   file name are not yet supported.  */
+   file names are not yet supported.  Thus the result must be an
+   ANSI-encoded string.  */
 char *
 w32_my_exename (void)
 {
   static char exename[MAX_PATH];
   if (!GetModuleFileNameA (NULL, exename, MAX_PATH))
     return NULL;
-  /* FIXME: Resolve possible symlinks in the last component of
-     exename, i.e. if the executable itself is a symlink.  */
+  /* The caller expects us to resolve all possible symlinks in the
+     last component of exename, i.e. if the executable itself is a
+     symlink to a file in another directory.  */
+  if (get_volume_info (exename, NULL)
+      && (volume_info.flags & FILE_SUPPORTS_REPARSE_POINTS) != 0)
+    {
+      /* chase_symlinks wants its argument in UTF-8.  */
+      char exename_utf8[MAX_UTF8_PATH];
+      filename_from_ansi (exename, exename_utf8);
+
+      /* If EXENAME is a symlink, replace it with its target.  */
+      char *tgt = chase_symlinks (exename_utf8);
+      if (tgt != exename_utf8)
+       filename_to_ansi (tgt, exename);
+    }
+
   return exename;
 }
 



reply via email to

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