Commit e4a8f6eb authored by Eli Zaretskii's avatar Eli Zaretskii

Fix the value of default-directory upon startup on MS-Windows

* src/w32.c (w32_get_current_directory): New function.
(GetCachedVolumeInformation, init_environment): Use it.
(w32_init_current_directory): New function.
* src/w32.h (w32_init_current_directory): Add prototype.
* src/emacs.c (main) [WINDOWSNT]: Use w32_init_current_directory
to get the accurate value of cwd.  This is needed to record
the correct directory in emacs_wd, which is now initialized
way earlier in the startup process, when init_environment was
not yet called.  For details, see the problems reported in
http://lists.gnu.org/archive/html/emacs-devel/2018-12/msg00068.html.
Reported by Angelo Graziosi <angelo.g0@libero.it>.
parent bcd74314
Pipeline #216 failed with stage
in 5 minutes and 18 seconds
......@@ -736,6 +736,8 @@ main (int argc, char **argv)
/* Initialize the codepage for file names, needed to decode
non-ASCII file names during startup. */
w32_init_file_name_codepage ();
/* Initialize the startup directory, needed for emacs_wd below. */
w32_init_current_directory ();
#endif
w32_init_main_thread ();
#endif
......@@ -816,6 +818,10 @@ main (int argc, char **argv)
exit (1);
}
original_pwd = emacs_wd;
#ifdef WINDOWSNT
/* Reinitialize Emacs's notion of the startup directory. */
w32_init_current_directory ();
#endif
emacs_wd = emacs_get_current_dir_name ();
}
......
......@@ -1771,7 +1771,40 @@ filename_from_ansi (const char *fn_in, char *fn_out)
/* The directory where we started, in UTF-8. */
static char startup_dir[MAX_UTF8_PATH];
/* Get the current working directory. */
/* Get the current working directory. The caller must arrange for CWD
to be allocated with enough space to hold a 260-char directory name
in UTF-8. IOW, the space should be at least MAX_UTF8_PATH bytes. */
static void
w32_get_current_directory (char *cwd)
{
/* FIXME: Do we need to resolve possible symlinks in startup_dir?
Does it matter anywhere in Emacs? */
if (w32_unicode_filenames)
{
wchar_t wstartup_dir[MAX_PATH];
if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
emacs_abort ();
filename_from_utf16 (wstartup_dir, cwd);
}
else
{
char astartup_dir[MAX_PATH];
if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
emacs_abort ();
filename_from_ansi (astartup_dir, cwd);
}
}
/* For external callers. Used by 'main' in emacs.c. */
void
w32_init_current_directory (void)
{
w32_get_current_directory (startup_dir);
}
/* Return the original directory where Emacs started. */
char *
getcwd (char *dir, int dirsize)
{
......@@ -2997,24 +3030,7 @@ init_environment (char ** argv)
}
/* Remember the initial working directory for getcwd. */
/* FIXME: Do we need to resolve possible symlinks in startup_dir?
Does it matter anywhere in Emacs? */
if (w32_unicode_filenames)
{
wchar_t wstartup_dir[MAX_PATH];
if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
emacs_abort ();
filename_from_utf16 (wstartup_dir, startup_dir);
}
else
{
char astartup_dir[MAX_PATH];
if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
emacs_abort ();
filename_from_ansi (astartup_dir, startup_dir);
}
w32_get_current_directory (startup_dir);
{
static char modname[MAX_PATH];
......@@ -3198,22 +3214,7 @@ GetCachedVolumeInformation (char * root_dir)
/* NULL for root_dir means use root from current directory. */
if (root_dir == NULL)
{
if (w32_unicode_filenames)
{
wchar_t curdirw[MAX_PATH];
if (GetCurrentDirectoryW (MAX_PATH, curdirw) == 0)
return NULL;
filename_from_utf16 (curdirw, default_root);
}
else
{
char curdira[MAX_PATH];
if (GetCurrentDirectoryA (MAX_PATH, curdira) == 0)
return NULL;
filename_from_ansi (curdira, default_root);
}
w32_get_current_directory (default_root);
parse_root (default_root, (const char **)&root_dir);
*root_dir = 0;
root_dir = default_root;
......
......@@ -201,6 +201,7 @@ extern int codepage_for_filenames (CPINFO *);
extern Lisp_Object ansi_encode_filename (Lisp_Object);
extern int w32_copy_file (const char *, const char *, int, int, int);
extern int w32_accessible_directory_p (const char *, ptrdiff_t);
extern void w32_init_current_directory (void);
extern BOOL init_winsock (int load_now);
extern void srandom (int);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment