On 11/20/12 12:13, Eli Zaretskii wrote: > Here's the patch for that: Thanks. Won't we need patches elswhere to match? Something like the following. I'm attaching a combined patch, relative to trunk bzr 110966. Also, how is this related to the "#define getcwd _getcwd" in lib-src/ntlib.h? === modified file 'nt/config.nt' --- nt/config.nt 2012-11-17 23:58:56 +0000 +++ nt/config.nt 2012-11-20 20:44:17 +0000 @@ -411,11 +411,10 @@ /* Define to 1 if you have the `getaddrinfo' function. */ #undef HAVE_GETADDRINFO -/* Define to 1 if you have the `getcwd' function. - If you think about defining HAVE_GETCWD, don't: the alternative - getwd is redefined on w32.c, and does not really return the current +/* Define to 1 if you have the `getcwd' function. This is + defined on w32.c, and does not really return the current directory, to get the desired results elsewhere in Emacs. */ -#undef HAVE_GETCWD +#define HAVE_GETCWD 1 /* Define to 1 if you have the `getdelim' function. */ #undef HAVE_GETDELIM === modified file 'src/fileio.c' --- src/fileio.c 2012-11-14 04:55:41 +0000 +++ src/fileio.c 2012-11-20 20:44:17 +0000 @@ -1133,7 +1133,7 @@ newdir = "/"; } else - getwd (adir); + getcwd (adir, MAXPATHLEN + 1); newdir = adir; } === modified file 'src/msdos.c' --- src/msdos.c 2012-11-05 03:18:32 +0000 +++ src/msdos.c 2012-11-20 20:44:17 +0000 @@ -3784,7 +3784,7 @@ Lisp_Object cmd; /* Get current directory as MSDOS cwd is not per-process. */ - getwd (oldwd); + getcwd (oldwd, sizeof oldwd); /* If argv[0] is the shell, it might come in any lettercase. Since `Fmember' is case-sensitive, we need to downcase === modified file 'src/sysdep.c' --- src/sysdep.c 2012-11-20 17:33:00 +0000 +++ src/sysdep.c 2012-11-20 20:44:17 +0000 @@ -101,7 +101,6 @@ #define _P_WAIT 0 int _cdecl _spawnlp (int, const char *, const char *, ...); int _cdecl _getpid (void); -extern char *getwd (char *); #endif #include "syssignal.h" @@ -504,7 +503,7 @@ const char *sh = 0; #ifdef DOS_NT /* MW, Aug 1993 */ - getwd (oldwd); + getcwd (oldwd, sizeof oldwd); if (sh == 0) sh = (char *) egetenv ("SUSPEND"); /* KFS, 1994-12-14 */ #endif === modified file 'src/w32.c' --- src/w32.c 2012-11-17 22:12:47 +0000 +++ src/w32.c 2012-11-20 20:44:17 +0000 @@ -901,8 +901,18 @@ /* Get the current working directory. */ char * -getwd (char *dir) +getcwd (char *dir, size_t dirsize) { + if (!dirsize) + { + errno = EINVAL; + return NULL; + } + if (dirsize <= strlen (startup_dir)) + { + errno = ERANGE; + return NULL; + } #if 0 if (GetCurrentDirectory (MAXPATHLEN, dir) > 0) return dir; @@ -1818,7 +1828,7 @@ memcpy (*envp, "COMSPEC=", 8); } - /* Remember the initial working directory for getwd. */ + /* 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 (!GetCurrentDirectory (MAXPATHLEN, startup_dir)) === modified file 'src/w32.h' --- src/w32.h 2012-10-17 19:02:44 +0000 +++ src/w32.h 2012-11-20 20:44:17 +0000 @@ -163,7 +163,7 @@ extern void register_child (int, int); extern void sys_sleep (int); -extern char *getwd (char *); +extern char *getcwd (char *, size_t); extern int sys_link (const char *, const char *); @@ -181,4 +181,3 @@ #endif /* HAVE_GNUTLS */ #endif /* EMACS_W32_H */ -