aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2018-12-07 10:54:57 +0200
committerEli Zaretskii2018-12-07 10:54:57 +0200
commite4a8f6ebbf4e8cf4d87d5b7b9940b61b51073fd3 (patch)
tree9fa8559e3e0c6cd38625eba0ccff94144d4e0691 /src
parentbcd74314626db88a8ff3c9deeb6ea7fbcd337413 (diff)
downloademacs-e4a8f6ebbf4e8cf4d87d5b7b9940b61b51073fd3.tar.gz
emacs-e4a8f6ebbf4e8cf4d87d5b7b9940b61b51073fd3.zip
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>.
Diffstat (limited to 'src')
-rw-r--r--src/emacs.c6
-rw-r--r--src/w32.c71
-rw-r--r--src/w32.h1
3 files changed, 43 insertions, 35 deletions
diff --git a/src/emacs.c b/src/emacs.c
index acb4959bfea..eddd729f0a4 100644
--- a/src/emacs.c
+++ b/src/emacs.c
@@ -736,6 +736,8 @@ main (int argc, char **argv)
736 /* Initialize the codepage for file names, needed to decode 736 /* Initialize the codepage for file names, needed to decode
737 non-ASCII file names during startup. */ 737 non-ASCII file names during startup. */
738 w32_init_file_name_codepage (); 738 w32_init_file_name_codepage ();
739 /* Initialize the startup directory, needed for emacs_wd below. */
740 w32_init_current_directory ();
739#endif 741#endif
740 w32_init_main_thread (); 742 w32_init_main_thread ();
741#endif 743#endif
@@ -816,6 +818,10 @@ main (int argc, char **argv)
816 exit (1); 818 exit (1);
817 } 819 }
818 original_pwd = emacs_wd; 820 original_pwd = emacs_wd;
821#ifdef WINDOWSNT
822 /* Reinitialize Emacs's notion of the startup directory. */
823 w32_init_current_directory ();
824#endif
819 emacs_wd = emacs_get_current_dir_name (); 825 emacs_wd = emacs_get_current_dir_name ();
820 } 826 }
821 827
diff --git a/src/w32.c b/src/w32.c
index 26cfae7a6af..dc8bed582c0 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -1771,7 +1771,40 @@ filename_from_ansi (const char *fn_in, char *fn_out)
1771/* The directory where we started, in UTF-8. */ 1771/* The directory where we started, in UTF-8. */
1772static char startup_dir[MAX_UTF8_PATH]; 1772static char startup_dir[MAX_UTF8_PATH];
1773 1773
1774/* Get the current working directory. */ 1774/* Get the current working directory. The caller must arrange for CWD
1775 to be allocated with enough space to hold a 260-char directory name
1776 in UTF-8. IOW, the space should be at least MAX_UTF8_PATH bytes. */
1777static void
1778w32_get_current_directory (char *cwd)
1779{
1780 /* FIXME: Do we need to resolve possible symlinks in startup_dir?
1781 Does it matter anywhere in Emacs? */
1782 if (w32_unicode_filenames)
1783 {
1784 wchar_t wstartup_dir[MAX_PATH];
1785
1786 if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
1787 emacs_abort ();
1788 filename_from_utf16 (wstartup_dir, cwd);
1789 }
1790 else
1791 {
1792 char astartup_dir[MAX_PATH];
1793
1794 if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
1795 emacs_abort ();
1796 filename_from_ansi (astartup_dir, cwd);
1797 }
1798}
1799
1800/* For external callers. Used by 'main' in emacs.c. */
1801void
1802w32_init_current_directory (void)
1803{
1804 w32_get_current_directory (startup_dir);
1805}
1806
1807/* Return the original directory where Emacs started. */
1775char * 1808char *
1776getcwd (char *dir, int dirsize) 1809getcwd (char *dir, int dirsize)
1777{ 1810{
@@ -2997,24 +3030,7 @@ init_environment (char ** argv)
2997 } 3030 }
2998 3031
2999 /* Remember the initial working directory for getcwd. */ 3032 /* Remember the initial working directory for getcwd. */
3000 /* FIXME: Do we need to resolve possible symlinks in startup_dir? 3033 w32_get_current_directory (startup_dir);
3001 Does it matter anywhere in Emacs? */
3002 if (w32_unicode_filenames)
3003 {
3004 wchar_t wstartup_dir[MAX_PATH];
3005
3006 if (!GetCurrentDirectoryW (MAX_PATH, wstartup_dir))
3007 emacs_abort ();
3008 filename_from_utf16 (wstartup_dir, startup_dir);
3009 }
3010 else
3011 {
3012 char astartup_dir[MAX_PATH];
3013
3014 if (!GetCurrentDirectoryA (MAX_PATH, astartup_dir))
3015 emacs_abort ();
3016 filename_from_ansi (astartup_dir, startup_dir);
3017 }
3018 3034
3019 { 3035 {
3020 static char modname[MAX_PATH]; 3036 static char modname[MAX_PATH];
@@ -3198,22 +3214,7 @@ GetCachedVolumeInformation (char * root_dir)
3198 /* NULL for root_dir means use root from current directory. */ 3214 /* NULL for root_dir means use root from current directory. */
3199 if (root_dir == NULL) 3215 if (root_dir == NULL)
3200 { 3216 {
3201 if (w32_unicode_filenames) 3217 w32_get_current_directory (default_root);
3202 {
3203 wchar_t curdirw[MAX_PATH];
3204
3205 if (GetCurrentDirectoryW (MAX_PATH, curdirw) == 0)
3206 return NULL;
3207 filename_from_utf16 (curdirw, default_root);
3208 }
3209 else
3210 {
3211 char curdira[MAX_PATH];
3212
3213 if (GetCurrentDirectoryA (MAX_PATH, curdira) == 0)
3214 return NULL;
3215 filename_from_ansi (curdira, default_root);
3216 }
3217 parse_root (default_root, (const char **)&root_dir); 3218 parse_root (default_root, (const char **)&root_dir);
3218 *root_dir = 0; 3219 *root_dir = 0;
3219 root_dir = default_root; 3220 root_dir = default_root;
diff --git a/src/w32.h b/src/w32.h
index 42b3d98245f..5054b400c5b 100644
--- a/src/w32.h
+++ b/src/w32.h
@@ -201,6 +201,7 @@ extern int codepage_for_filenames (CPINFO *);
201extern Lisp_Object ansi_encode_filename (Lisp_Object); 201extern Lisp_Object ansi_encode_filename (Lisp_Object);
202extern int w32_copy_file (const char *, const char *, int, int, int); 202extern int w32_copy_file (const char *, const char *, int, int, int);
203extern int w32_accessible_directory_p (const char *, ptrdiff_t); 203extern int w32_accessible_directory_p (const char *, ptrdiff_t);
204extern void w32_init_current_directory (void);
204 205
205extern BOOL init_winsock (int load_now); 206extern BOOL init_winsock (int load_now);
206extern void srandom (int); 207extern void srandom (int);