diff options
| author | Eli Zaretskii | 2018-12-07 10:54:57 +0200 |
|---|---|---|
| committer | Eli Zaretskii | 2018-12-07 10:54:57 +0200 |
| commit | e4a8f6ebbf4e8cf4d87d5b7b9940b61b51073fd3 (patch) | |
| tree | 9fa8559e3e0c6cd38625eba0ccff94144d4e0691 /src/w32.c | |
| parent | bcd74314626db88a8ff3c9deeb6ea7fbcd337413 (diff) | |
| download | emacs-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/w32.c')
| -rw-r--r-- | src/w32.c | 71 |
1 files changed, 36 insertions, 35 deletions
| @@ -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. */ |
| 1772 | static char startup_dir[MAX_UTF8_PATH]; | 1772 | static 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. */ | ||
| 1777 | static void | ||
| 1778 | w32_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. */ | ||
| 1801 | void | ||
| 1802 | w32_init_current_directory (void) | ||
| 1803 | { | ||
| 1804 | w32_get_current_directory (startup_dir); | ||
| 1805 | } | ||
| 1806 | |||
| 1807 | /* Return the original directory where Emacs started. */ | ||
| 1775 | char * | 1808 | char * |
| 1776 | getcwd (char *dir, int dirsize) | 1809 | getcwd (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; |