/[emacs]/emacs/src/sysdep.c
ViewVC logotype

Diff of /emacs/src/sysdep.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.266 by ttn, Sun Aug 7 12:33:18 2005 UTC revision 1.267 by eliz, Sat Sep 10 11:29:15 2005 UTC
# Line 258  void hft_reset (); Line 258  void hft_reset ();
258    
259  SIGMASKTYPE sigprocmask_set;  SIGMASKTYPE sigprocmask_set;
260    
261    
262    #ifndef HAVE_CURRENT_DIR_NAME
263    
264    /* Return the current working directory.  Returns NULL on errors.
265       Any other returned value must be freed with free. This is used
266       only when get_current_dir_name is not defined on the system.  */
267    char*
268    get_current_dir_name ()
269    {
270      char *buf;
271      char *pwd;
272      struct stat dotstat, pwdstat;
273      /* If PWD is accurate, use it instead of calling getwd.  PWD is
274         sometimes a nicer name, and using it may avoid a fatal error if a
275         parent directory is searchable but not readable.  */
276        if ((pwd = getenv ("PWD")) != 0
277          && (IS_DIRECTORY_SEP (*pwd) || (*pwd && IS_DEVICE_SEP (pwd[1])))
278          && stat (pwd, &pwdstat) == 0
279          && stat (".", &dotstat) == 0
280          && dotstat.st_ino == pwdstat.st_ino
281          && dotstat.st_dev == pwdstat.st_dev
282    #ifdef MAXPATHLEN
283          && strlen (pwd) < MAXPATHLEN
284    #endif
285          )
286        {
287          buf = (char *) malloc (strlen (pwd) + 1);
288          if (!buf)
289            return NULL;
290          strcpy (buf, pwd);
291        }
292    #ifdef HAVE_GETCWD
293      else
294        {
295          size_t buf_size = 1024;
296          buf = (char *) malloc (buf_size);
297          if (!buf)
298            return NULL;
299          for (;;)
300            {
301              if (getcwd (buf, buf_size) == buf)
302                break;
303              if (errno != ERANGE)
304                {
305                  int tmp_errno = errno;
306                  free (buf);
307                  errno = tmp_errno;
308                  return NULL;
309                }
310              buf_size *= 2;
311              buf = (char *) realloc (buf, buf_size);
312              if (!buf)
313                return NULL;
314            }
315        }
316    #else
317      else
318        {
319          /* We need MAXPATHLEN here.  */
320          buf = (char *) malloc (MAXPATHLEN + 1);
321          if (!buf)
322            return NULL;
323          if (getwd (buf) == NULL)
324            {
325              int tmp_errno = errno;
326              free (buf);
327              errno = tmp_errno;
328              return NULL;
329            }
330        }
331    #endif
332      return buf;
333    }
334    #endif
335    
336    
337  /* Specify a different file descriptor for further input operations.  */  /* Specify a different file descriptor for further input operations.  */
338    

Legend:
Removed from v.1.266  
changed lines
  Added in v.1.267

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26