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;
}