aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJim Blandy <[email protected]>1992-11-07 07:00:04 +0000
committerJim Blandy <[email protected]>1992-11-07 07:00:04 +0000
commit2381d133384a57886ae6509b4f2712cc706999d2 (patch)
tree44496e8515caa7bc57aed2567110f68910008d9e /src
parentd0f7e1511e23359d58184e59dccffa61f03ee0b8 (diff)
* buffer.c (init_buffer): If PWD is accurate, use it instead of
calling getwd. #include <sys/types.h> and <sys/stat.h>, for the call to stat.
Diffstat (limited to 'src')
-rw-r--r--src/buffer.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 83f7826b5f..74a9ad78dd 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -18,6 +18,8 @@ along with GNU Emacs; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
+#include <sys/types.h>
+#include <sys/stat.h>
#include <sys/param.h>
#ifndef MAXPATHLEN
@@ -1359,9 +1361,21 @@ init_buffer_once ()
init_buffer ()
{
char buf[MAXPATHLEN+1];
+ char *pwd;
+ struct stat dotstat, pwdstat;
Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
- if (getwd (buf) == 0)
+
+ /* If PWD is accurate, use it instead of calling getwd. This is faster
+ when PWD is right, and may avoid a fatal error. */
+ if ((pwd = getenv ("PWD")) != 0 && *pwd == '/'
+ && stat (pwd, &pwdstat) == 0
+ && stat (".", &dotstat) == 0
+ && dotstat.st_ino == pwdstat.st_ino
+ && dotstat.st_dev == pwdstat.st_dev
+ && strlen (pwd) < MAXPATHLEN)
+ strcpy (buf, pwd);
+ else if (getwd (buf) == 0)
fatal ("`getwd' failed: %s.\n", buf);
#ifndef VMS