From e5a0d4c42583fe38e38ab7782b8928ca54f82fad Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 3 Mar 2021 19:58:20 +0200 Subject: [PATCH] Avoid aborting on MS-Windows at startup * 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 | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/emacs.c b/src/emacs.c index d541b41f3f1..ec62c19e388 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -37,6 +37,7 @@ along with GNU Emacs. If not, see . */ #include #include #include +#include /* 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)) -- 2.39.2