]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid aborting on MS-Windows at startup
authorEli Zaretskii <eliz@gnu.org>
Wed, 3 Mar 2021 17:58:20 +0000 (19:58 +0200)
committerEli Zaretskii <eliz@gnu.org>
Wed, 3 Mar 2021 17:58:20 +0000 (19:58 +0200)
* src/emacs.c (set_invocation_vars) [WINDOWSNT]: If argv0 is not
an absolute file name, obtain the absolute file name of the Emacs
executable from 'w32_my_exename'.

src/emacs.c

index d541b41f3f102e3c15a83f13da17f1164e9b86c2..ec62c19e3884ce0829f8e549f1e7ac0029053987 100644 (file)
@@ -37,6 +37,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include <fcntl.h>
 #include <sys/socket.h>
 #include <mbstring.h>
+#include <filename.h>  /* for IS_ABSOLUTE_FILE_NAME */
 #include "w32.h"
 #include "w32heap.h"
 #endif
@@ -433,6 +434,12 @@ set_invocation_vars (char *argv0, char const *original_pwd)
   {
     char argv0_1[MAX_UTF8_PATH];
 
+    /* Avoid calling 'openp' below, as we aren't ready for that yet:
+       emacs_dir is not yet defined in the environment, and therefore
+       emacs_root_dir, called by expand-file-name, will abort.  */
+    if (!IS_ABSOLUTE_FILE_NAME (argv0))
+      argv0 = w32_my_exename ();
+
     if (filename_from_ansi (argv0, argv0_1) == 0)
       raw_name = build_unibyte_string (argv0_1);
     else
@@ -451,6 +458,11 @@ set_invocation_vars (char *argv0, char const *original_pwd)
   Vinvocation_name = Ffile_name_nondirectory (raw_name);
   Vinvocation_directory = Ffile_name_directory (raw_name);
 
+#ifdef WINDOWSNT
+  eassert (!NILP (Vinvocation_directory)
+          && !NILP (Ffile_name_absolute_p (Vinvocation_directory)));
+#endif
+
   /* If we got no directory in argv0, search PATH to find where
      Emacs actually came from.  */
   if (NILP (Vinvocation_directory))