aboutsummaryrefslogtreecommitdiffstats
path: root/src/buffer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c45
1 files changed, 15 insertions, 30 deletions
diff --git a/src/buffer.c b/src/buffer.c
index 30626f11a24..fb1ff1c22e9 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>
@@ -5115,7 +5111,6 @@ init_buffer_once ()
5115void 5111void
5116init_buffer () 5112init_buffer ()
5117{ 5113{
5118 char buf[MAXPATHLEN + 1];
5119 char *pwd; 5114 char *pwd;
5120 struct stat dotstat, pwdstat; 5115 struct stat dotstat, pwdstat;
5121 Lisp_Object temp; 5116 Lisp_Object temp;
@@ -5138,40 +5133,28 @@ init_buffer ()
5138 if (NILP (buffer_defaults.enable_multibyte_characters)) 5133 if (NILP (buffer_defaults.enable_multibyte_characters))
5139 Fset_buffer_multibyte (Qnil); 5134 Fset_buffer_multibyte (Qnil);
5140 5135
5141 /* If PWD is accurate, use it instead of calling getwd. PWD is 5136 pwd = get_current_dir_name ();
5142 sometimes a nicer name, and using it may avoid a fatal error if a 5137
5143 parent directory is searchable but not readable. */ 5138 if (!pwd)
5144 if ((pwd = getenv ("PWD")) != 0 5139 fatal ("`get_current_dir_name' 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 5140
5160#ifndef VMS 5141#ifndef VMS
5161 /* Maybe this should really use some standard subroutine 5142 /* Maybe this should really use some standard subroutine
5162 whose definition is filename syntax dependent. */ 5143 whose definition is filename syntax dependent. */
5163 rc = strlen (buf); 5144 rc = strlen (pwd);
5164 if (!(IS_DIRECTORY_SEP (buf[rc - 1]))) 5145 if (!(IS_DIRECTORY_SEP (pwd[rc - 1])))
5165 { 5146 {
5166 buf[rc] = DIRECTORY_SEP; 5147 /* Grow buffer to add directory separator and '\0'. */
5167 buf[rc + 1] = '\0'; 5148 pwd = (char *) xrealloc (pwd, rc + 2);
5149 pwd[rc] = DIRECTORY_SEP;
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 moment, we still don't know how to decode the
5174 direcotry name. So, we keep the bytes in multibyte form so 5157 directory name. So, we keep the bytes in multibyte form so
5175 that ENCODE_FILE correctly gets the original bytes. */ 5158 that ENCODE_FILE correctly gets the original bytes. */
5176 current_buffer->directory 5159 current_buffer->directory
5177 = string_to_multibyte (current_buffer->directory); 5160 = string_to_multibyte (current_buffer->directory);
@@ -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 */