summaryrefslogtreecommitdiff
path: root/src/w32.c
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2021-05-27 16:31:14 +0300
committerEli Zaretskii <eliz@gnu.org>2021-05-27 16:31:14 +0300
commitd3817ad6ce7b719c89d4049bdd12b168e3053a76 (patch)
tree6267b049782f4d4256afa3d9eaea0a05520fceed /src/w32.c
parent00f5c2fa3834d1beb780cae22921126a1f9ddb1d (diff)
downloademacs-d3817ad6ce7b719c89d4049bdd12b168e3053a76.tar.gz
emacs-d3817ad6ce7b719c89d4049bdd12b168e3053a76.tar.bz2
emacs-d3817ad6ce7b719c89d4049bdd12b168e3053a76.zip
Fix resolution of symlinks during dumping
* src/comp.c (Fcomp_el_to_eln_rel_filename): Don't use 'file-truename', as it is only available once files.el is loaded, which doesn't work during dumping, until loadup loads files.el. Instead, use 'realpath'. (Bug#48578) * src/w32.c (realpath): New function. * src/w32.h (realpath): Add prototype. * nt/mingw-cfg.site (ac_cv_func_realpath) (gl_cv_func_realpath_works): Define to "yes", as this function is now implemented in w32.c.
Diffstat (limited to 'src/w32.c')
-rw-r--r--src/w32.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/w32.c b/src/w32.c
index 26cc28f877c..968b4bbe489 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -10587,6 +10587,45 @@ w32_my_exename (void)
return exename;
}
+/* Emulate Posix 'realpath'. This is needed in
+ comp-el-to-eln-rel-filename. */
+char *
+realpath (const char *file_name, char *resolved_name)
+{
+ char *tgt = chase_symlinks (file_name);
+ char target[MAX_UTF8_PATH];
+
+ if (tgt == file_name)
+ {
+ /* If FILE_NAME is not a symlink, chase_symlinks returns its
+ argument, possibly not in canonical absolute form. Make sure
+ we return a canonical file name. */
+ if (w32_unicode_filenames)
+ {
+ wchar_t file_w[MAX_PATH], tgt_w[MAX_PATH];
+
+ filename_to_utf16 (file_name, file_w);
+ if (GetFullPathNameW (file_w, MAX_PATH, tgt_w, NULL) == 0)
+ return NULL;
+ filename_from_utf16 (tgt_w, target);
+ }
+ else
+ {
+ char file_a[MAX_PATH], tgt_a[MAX_PATH];
+
+ filename_to_ansi (file_name, file_a);
+ if (GetFullPathNameA (file_a, MAX_PATH, tgt_a, NULL) == 0)
+ return NULL;
+ filename_from_ansi (tgt_a, target);
+ }
+ tgt = target;
+ }
+
+ if (resolved_name)
+ return strcpy (resolved_name, tgt);
+ return xstrdup (tgt);
+}
+
/*
globals_of_w32 is used to initialize those global variables that
must always be initialized on startup even when the global variable