comparison src/buffer.c @ 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 c090f7dcfd27
children f84e400808d0
comparison
equal deleted inserted replaced
1562:00ba13693a97 1563:e721339972b0
16 You should have received a copy of the GNU General Public License 16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to 17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19 19
20 20
21 #include <sys/types.h>
22 #include <sys/stat.h>
21 #include <sys/param.h> 23 #include <sys/param.h>
22 24
23 #ifndef MAXPATHLEN 25 #ifndef MAXPATHLEN
24 /* in 4.1, param.h fails to define this. */ 26 /* in 4.1, param.h fails to define this. */
25 #define MAXPATHLEN 1024 27 #define MAXPATHLEN 1024
1357 } 1359 }
1358 1360
1359 init_buffer () 1361 init_buffer ()
1360 { 1362 {
1361 char buf[MAXPATHLEN+1]; 1363 char buf[MAXPATHLEN+1];
1364 char *pwd;
1365 struct stat dotstat, pwdstat;
1362 1366
1363 Fset_buffer (Fget_buffer_create (build_string ("*scratch*"))); 1367 Fset_buffer (Fget_buffer_create (build_string ("*scratch*")));
1364 if (getwd (buf) == 0) 1368
1369 /* If PWD is accurate, use it instead of calling getwd. This is faster
1370 when PWD is right, and may avoid a fatal error. */
1371 if ((pwd = getenv ("PWD")) != 0 && *pwd == '/'
1372 && stat (pwd, &pwdstat) == 0
1373 && stat (".", &dotstat) == 0
1374 && dotstat.st_ino == pwdstat.st_ino
1375 && dotstat.st_dev == pwdstat.st_dev
1376 && strlen (pwd) < MAXPATHLEN)
1377 strcpy (buf, pwd);
1378 else if (getwd (buf) == 0)
1365 fatal ("`getwd' failed: %s.\n", buf); 1379 fatal ("`getwd' failed: %s.\n", buf);
1366 1380
1367 #ifndef VMS 1381 #ifndef VMS
1368 /* Maybe this should really use some standard subroutine 1382 /* Maybe this should really use some standard subroutine
1369 whose definition is filename syntax dependent. */ 1383 whose definition is filename syntax dependent. */