aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEli Zaretskii2012-06-29 16:11:54 +0300
committerEli Zaretskii2012-06-29 16:11:54 +0300
commit8d38f4616b85a226221e599c34e55298bb54d3cc (patch)
tree8edee1c820e7c335ede557b632786bb4e7ff4512 /src
parent2af3565e0f2b325924e4adad26a08b442fa022ac (diff)
downloademacs-8d38f4616b85a226221e599c34e55298bb54d3cc.tar.gz
emacs-8d38f4616b85a226221e599c34e55298bb54d3cc.zip
Fix the current directory of the Emacs process on MS-Windows.
src/w32.c (getwd): Adjust commentary about startup_dir. (init_environment): Always call sys_access, even in non-MSVC builds. Don't chdir to the directory of the Emacs executable. This undoes code from 1997 which was justified by the need to "avoid conflicts when removing and renaming directories". But its downside was that every relative file name was being interpreted relative to the directory of the Emacs executable, which can never be TRT. In particular, it broke sys_access when called with relative file names. (sys_access): Map GetLastError to errno.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog13
-rw-r--r--src/w32.c41
2 files changed, 29 insertions, 25 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e5517eeb8db..a75ed5cbc37 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,16 @@
12012-06-29 Eli Zaretskii <eliz@gnu.org>
2
3 * w32.c (getwd): Adjust commentary about startup_dir.
4 (init_environment): Always call sys_access, even in non-MSVC
5 builds. Don't chdir to the directory of the Emacs executable.
6 This undoes code from 1997 which was justified by the need to
7 "avoid conflicts when removing and renaming directories". But its
8 downside was that every relative file name was being interpreted
9 relative to the directory of the Emacs executable, which can never
10 be TRT. In particular, it broke sys_access when called with
11 relative file names.
12 (sys_access): Map GetLastError to errno.
13
12012-06-29 Dmitry Antipov <dmantipov@yandex.ru> 142012-06-29 Dmitry Antipov <dmantipov@yandex.ru>
2 15
3 * window.h (struct window): Change type of 'fringes_outside_margins' 16 * window.h (struct window): Change type of 'fringes_outside_margins'
diff --git a/src/w32.c b/src/w32.c
index b0272c64871..691d80a6313 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -778,9 +778,8 @@ getwd (char *dir)
778 return dir; 778 return dir;
779 return NULL; 779 return NULL;
780#else 780#else
781 /* Emacs doesn't actually change directory itself, and we want to 781 /* Emacs doesn't actually change directory itself, it stays in the
782 force our real wd to be where emacs.exe is to avoid unnecessary 782 same directory where it was started. */
783 conflicts when trying to rename or delete directories. */
784 strcpy (dir, startup_dir); 783 strcpy (dir, startup_dir);
785 return dir; 784 return dir;
786#endif 785#endif
@@ -1536,12 +1535,7 @@ init_environment (char ** argv)
1536 read-only filesystem, like CD-ROM or a write-protected floppy. 1535 read-only filesystem, like CD-ROM or a write-protected floppy.
1537 The only way to be really sure is to actually create a file and 1536 The only way to be really sure is to actually create a file and
1538 see if it succeeds. But I think that's too much to ask. */ 1537 see if it succeeds. But I think that's too much to ask. */
1539#ifdef _MSC_VER
1540 /* MSVC's _access crashes with D_OK. */
1541 if (tmp && sys_access (tmp, D_OK) == 0) 1538 if (tmp && sys_access (tmp, D_OK) == 0)
1542#else
1543 if (tmp && _access (tmp, D_OK) == 0)
1544#endif
1545 { 1539 {
1546 char * var = alloca (strlen (tmp) + 8); 1540 char * var = alloca (strlen (tmp) + 8);
1547 sprintf (var, "TMPDIR=%s", tmp); 1541 sprintf (var, "TMPDIR=%s", tmp);
@@ -1781,27 +1775,15 @@ init_environment (char ** argv)
1781 memcpy (*envp, "COMSPEC=", 8); 1775 memcpy (*envp, "COMSPEC=", 8);
1782 } 1776 }
1783 1777
1784 /* Remember the initial working directory for getwd, then make the 1778 /* Remember the initial working directory for getwd. */
1785 real wd be the location of emacs.exe to avoid conflicts when
1786 renaming or deleting directories. (We also don't call chdir when
1787 running subprocesses for the same reason.) */
1788 if (!GetCurrentDirectory (MAXPATHLEN, startup_dir)) 1779 if (!GetCurrentDirectory (MAXPATHLEN, startup_dir))
1789 abort (); 1780 abort ();
1790 1781
1791 { 1782 {
1792 char *p;
1793 static char modname[MAX_PATH]; 1783 static char modname[MAX_PATH];
1794 1784
1795 if (!GetModuleFileName (NULL, modname, MAX_PATH)) 1785 if (!GetModuleFileName (NULL, modname, MAX_PATH))
1796 abort (); 1786 abort ();
1797 if ((p = strrchr (modname, '\\')) == NULL)
1798 abort ();
1799 *p = 0;
1800
1801 SetCurrentDirectory (modname);
1802
1803 /* Ensure argv[0] has the full path to Emacs. */
1804 *p = '\\';
1805 argv[0] = modname; 1787 argv[0] = modname;
1806 } 1788 }
1807 1789
@@ -2667,7 +2649,8 @@ sys_access (const char * path, int mode)
2667{ 2649{
2668 DWORD attributes; 2650 DWORD attributes;
2669 2651
2670 /* MSVC implementation doesn't recognize D_OK. */ 2652 /* MSVCRT implementation of 'access' doesn't recognize D_OK, and its
2653 newer versions blow up when passed D_OK. */
2671 path = map_w32_filename (path, NULL); 2654 path = map_w32_filename (path, NULL);
2672 if (is_unc_volume (path)) 2655 if (is_unc_volume (path))
2673 { 2656 {
@@ -2679,9 +2662,17 @@ sys_access (const char * path, int mode)
2679 } 2662 }
2680 else if ((attributes = GetFileAttributes (path)) == -1) 2663 else if ((attributes = GetFileAttributes (path)) == -1)
2681 { 2664 {
2682 /* Should try mapping GetLastError to errno; for now just indicate 2665 DWORD w32err = GetLastError ();
2683 that path doesn't exist. */ 2666
2684 errno = EACCES; 2667 switch (w32err)
2668 {
2669 case ERROR_FILE_NOT_FOUND:
2670 errno = ENOENT;
2671 break;
2672 default:
2673 errno = EACCES;
2674 break;
2675 }
2685 return -1; 2676 return -1;
2686 } 2677 }
2687 if ((mode & X_OK) != 0 && !is_exec (path)) 2678 if ((mode & X_OK) != 0 && !is_exec (path))