diff --git a/src/emacs.c b/src/emacs.c index 059e1c6d8f..ad92fd6fca 100644 --- a/src/emacs.c +++ b/src/emacs.c @@ -864,15 +864,51 @@ load_pdump (int argc, char **argv) path_exec = w32_relocate (path_exec); #endif - /* Look for "emacs.pdmp" in PATH_EXEC. We hardcode "emacs" in - "emacs.pdmp" so that the Emacs binary still works if the user - copies and renames it. */ - const char *argv0_base = "emacs"; + /* Look for basename(argv0)+".pdmp" in PATH_EXEC. + This way, they can rename both the executable and its pdump + file in PATH_EXEC, and have several Emacs configurations in + the same versioned libexec subdirectory. */ + char *p, *last_sep = NULL; + for (p = argv[0]; *p; p++) + { + if (IS_DIRECTORY_SEP (*p)) + last_sep = p; + } + const char *argv0_base = last_sep ? last_sep + 1 : argv[0]; ptrdiff_t needed = (strlen (path_exec) + 1 + strlen (argv0_base) + strlen (suffix) + 1); + if (bufsize < needed) + { + xfree (dump_file); + dump_file = xmalloc (needed); + } +#ifdef DOS_NT + ptrdiff_t argv0_len = strlen (argv0_base); + if (argv0_len >= 4 + && c_strcasecmp (argv0_base + argv0_len - 4, ".exe") == 0) + sprintf (dump_file, "%s%c%.*s%s", path_exec, DIRECTORY_SEP, + (int)(argv0_len - 4), argv0_base, suffix); + else +#endif + sprintf (dump_file, "%s%c%s%s", + path_exec, DIRECTORY_SEP, argv0_base, suffix); + result = pdumper_load (dump_file); + + if (result == PDUMPER_LOAD_SUCCESS) + goto out; + + /* Finally, look for "emacs.pdmp" in PATH_EXEC. We hardcode "emacs" in + "emacs.pdmp" so that the Emacs binary still works if the user + copies and renames it. */ + argv0_base = "emacs"; + needed = (strlen (path_exec) + + 1 + + strlen (argv0_base) + + strlen (suffix) + + 1); if (bufsize < needed) { xfree (dump_file); @@ -882,42 +918,6 @@ load_pdump (int argc, char **argv) path_exec, DIRECTORY_SEP, argv0_base, suffix); result = pdumper_load (dump_file); - if (result == PDUMPER_LOAD_FILE_NOT_FOUND) - { - /* Finally, look for basename(argv0)+".pdmp" in PATH_EXEC. - This way, they can rename both the executable and its pdump - file in PATH_EXEC, and have several Emacs configurations in - the same versioned libexec subdirectory. */ - char *p, *last_sep = NULL; - for (p = argv[0]; *p; p++) - { - if (IS_DIRECTORY_SEP (*p)) - last_sep = p; - } - argv0_base = last_sep ? last_sep + 1 : argv[0]; - ptrdiff_t needed = (strlen (path_exec) - + 1 - + strlen (argv0_base) - + strlen (suffix) - + 1); - if (bufsize < needed) - { - xfree (dump_file); - dump_file = xmalloc (needed); - } -#ifdef DOS_NT - ptrdiff_t argv0_len = strlen (argv0_base); - if (argv0_len >= 4 - && c_strcasecmp (argv0_base + argv0_len - 4, ".exe") == 0) - sprintf (dump_file, "%s%c%.*s%s", path_exec, DIRECTORY_SEP, - (int)(argv0_len - 4), argv0_base, suffix); - else -#endif - sprintf (dump_file, "%s%c%s%s", - path_exec, DIRECTORY_SEP, argv0_base, suffix); - result = pdumper_load (dump_file); - } - if (result != PDUMPER_LOAD_SUCCESS) { if (result != PDUMPER_LOAD_FILE_NOT_FOUND)