[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] master e4a8f6e: Fix the value of default-directory upon st
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] master e4a8f6e: Fix the value of default-directory upon startup on MS-Windows |
Date: |
Fri, 7 Dec 2018 03:56:43 -0500 (EST) |
branch: master
commit e4a8f6ebbf4e8cf4d87d5b7b9940b61b51073fd3
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>
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 <address@hidden>.
---
src/emacs.c | 6 ++++++
src/w32.c | 71 +++++++++++++++++++++++++++++++------------------------------
src/w32.h | 1 +
3 files changed, 43 insertions(+), 35 deletions(-)
diff --git a/src/emacs.c b/src/emacs.c
index acb4959..eddd729 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -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 ();
}
diff --git a/src/w32.c b/src/w32.c
index 26cfae7..dc8bed5 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -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;
diff --git a/src/w32.h b/src/w32.h
index 42b3d98..5054b40 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -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);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] master e4a8f6e: Fix the value of default-directory upon startup on MS-Windows,
Eli Zaretskii <=