aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 30626f11a24..b0227031ac7 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -32,10 +32,6 @@ Boston, MA 02110-1301, USA. */
32extern int errno; 32extern int errno;
33#endif 33#endif
34 34
35#ifndef MAXPATHLEN
36/* in 4.1 [probably SunOS? -stef] , param.h fails to define this. */
37#define MAXPATHLEN 1024
38#endif /* not MAXPATHLEN */
39 35
40#ifdef HAVE_UNISTD_H 36#ifdef HAVE_UNISTD_H
41#include <unistd.h> 37#include <unistd.h>
@@ -54,6 +50,8 @@ extern int errno;
54#include "keymap.h" 50#include "keymap.h"
55#include "frame.h" 51#include "frame.h"
56 52
53extern char * get_current_dir_name ();
54
57struct buffer *current_buffer; /* the current buffer */ 55struct buffer *current_buffer; /* the current buffer */
58 56
59/* First buffer in chain of all buffers (in reverse order of creation). 57/* First buffer in chain of all buffers (in reverse order of creation).
@@ -5115,7 +5113,6 @@ init_buffer_once ()
5115void 5113void
5116init_buffer () 5114init_buffer ()
5117{ 5115{
5118 char buf[MAXPATHLEN + 1];
5119 char *pwd; 5116 char *pwd;
5120 struct stat dotstat, pwdstat; 5117 struct stat dotstat, pwdstat;
5121 Lisp_Object temp; 5118 Lisp_Object temp;
@@ -5138,37 +5135,23 @@ init_buffer ()
5138 if (NILP (buffer_defaults.enable_multibyte_characters)) 5135 if (NILP (buffer_defaults.enable_multibyte_characters))
5139 Fset_buffer_multibyte (Qnil); 5136 Fset_buffer_multibyte (Qnil);
5140 5137
5141 /* If PWD is accurate, use it instead of calling getwd. PWD is 5138 pwd = get_current_dir_name ();
5142 sometimes a nicer name, and using it may avoid a fatal error if a 5139
5143 parent directory is searchable but not readable. */ 5140 if(!pwd)
5144 if ((pwd = getenv ("PWD")) != 0 5141 fatal ("`get_cwd' failed: %s\n", strerror (errno));
5145 && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
5146 && stat (pwd, &pwdstat) == 0
5147 && stat (".", &dotstat) == 0
5148 && dotstat.st_ino == pwdstat.st_ino
5149 && dotstat.st_dev == pwdstat.st_dev
5150 && strlen (pwd) < MAXPATHLEN)
5151 strcpy (buf, pwd);
5152#ifdef HAVE_GETCWD
5153 else if (getcwd (buf, MAXPATHLEN+1) == 0)
5154 fatal ("`getcwd' failed: %s\n", strerror (errno));
5155#else
5156 else if (getwd (buf) == 0)
5157 fatal ("`getwd' failed: %s\n", buf);
5158#endif
5159 5142
5160#ifndef VMS 5143#ifndef VMS
5161 /* Maybe this should really use some standard subroutine 5144 /* Maybe this should really use some standard subroutine
5162 whose definition is filename syntax dependent. */ 5145 whose definition is filename syntax dependent. */
5163 rc = strlen (buf); 5146 rc = strlen (pwd);
5164 if (!(IS_DIRECTORY_SEP (buf[rc - 1]))) 5147 if (!(IS_DIRECTORY_SEP (pwd[rc - 1])))
5165 { 5148 {
5166 buf[rc] = DIRECTORY_SEP; 5149 pwd[rc] = DIRECTORY_SEP;
5167 buf[rc + 1] = '\0'; 5150 pwd[rc + 1] = '\0';
5168 } 5151 }
5169#endif /* not VMS */ 5152#endif /* not VMS */
5170 5153
5171 current_buffer->directory = make_unibyte_string (buf, strlen (buf)); 5154 current_buffer->directory = make_unibyte_string (pwd, strlen (pwd));
5172 if (! NILP (buffer_defaults.enable_multibyte_characters)) 5155 if (! NILP (buffer_defaults.enable_multibyte_characters))
5173 /* At this momemnt, we still don't know how to decode the 5156 /* At this momemnt, we still don't know how to decode the
5174 direcotry name. So, we keep the bytes in multibyte form so 5157 direcotry name. So, we keep the bytes in multibyte form so
@@ -5190,6 +5173,8 @@ init_buffer ()
5190 5173
5191 temp = get_minibuffer (0); 5174 temp = get_minibuffer (0);
5192 XBUFFER (temp)->directory = current_buffer->directory; 5175 XBUFFER (temp)->directory = current_buffer->directory;
5176
5177 free (pwd);
5193} 5178}
5194 5179
5195/* initialize the buffer routines */ 5180/* initialize the buffer routines */