changeset 1563:e721339972b0

* 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.
author Jim Blandy <jimb@redhat.com>
date Sat, 07 Nov 1992 07:00:04 +0000
parents 00ba13693a97
children b327816041d1
files src/buffer.c
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/buffer.c	Sat Nov 07 06:59:38 1992 +0000
+++ b/src/buffer.c	Sat Nov 07 07:00:04 1992 +0000
@@ -18,6 +18,8 @@
 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 ()
 {
   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