[Message Prev][Message Next][Thread Prev][Thread Next][Message Index][Thread Index]

[MD:2802]NTEmacsen crashed, when expand-file-name.



> From: Andrew Innes <andrewi@xxxxxxx>
> Date: 17 Dec 2001 18:14:38 +0000
> 
> > Why is it better to look at the location of emacs.exe instead of the
> > current drive?  The former could be a fallback, but why not try
> > _getdisk first?
> 
> In NT-Emacs, they will give the same answer (or would, except MSVC
> doesn't seem to provide a _getdisk function).  I made that change quite
> a while ago to avoid problems where Emacs would change its cwd to the
> directory where it needs to run or start a subprocess and then leave it
> there until the next subprocess is started.

Thanks for the tips.

Do the changes below look right?  I installed them after testing in
the MS-DOS version; could someone please see if the Windows version
does TRT after this change?


2001-12-19  Eli Zaretskii  <eliz@xxxxxxxxxxxxx>

	* w32.c (emacs_root_dir): New function.

	* msdos.c (emacs_root_dir): New function.

	* fileio.c (Fexpand_file_name) [DOS_NT]: Use the root directory
	of the current drive as the fallback for default_directory.


Index: src/fileio.c
===================================================================
RCS file: /cvs/emacs/src/fileio.c,v
retrieving revision 1.434
retrieving revision 1.435
diff -c -r1.434 -r1.435
*** src/fileio.c	12 Dec 2001 22:53:16 -0000	1.434
--- src/fileio.c	19 Dec 2001 18:55:01 -0000	1.435
***************
*** 1038,1044 ****
    if (NILP (default_directory))
      default_directory = current_buffer->directory;
    if (! STRINGP (default_directory))
!     default_directory = build_string ("/");
  
    if (!NILP (default_directory))
      {
--- 1038,1060 ----
    if (NILP (default_directory))
      default_directory = current_buffer->directory;
    if (! STRINGP (default_directory))
!     {
! #ifdef DOS_NT
!       /* "/" is not considered a root directory on DOS_NT, so using "/"
! 	 here causes an infinite recursion in, e.g., the following:
! 
!             (let (default-directory)
! 	      (expand-file-name "a"))
! 
! 	 To avoid this, we set default_directory to the root of the
! 	 current drive.  */
!       extern char *emacs_root_dir (void);
! 
!       default_directory = build_string (emacs_root_dir ());
! #else
!       default_directory = build_string ("/");
! #endif
!     }
  
    if (!NILP (default_directory))
      {

Index: src/msdos.c
===================================================================
RCS file: /cvs/emacs/src/msdos.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -c -r1.158 -r1.159
*** src/msdos.c	11 Dec 2001 06:22:23 -0000	1.158
--- src/msdos.c	19 Dec 2001 18:56:00 -0000	1.159
***************
*** 38,43 ****
--- 38,44 ----
  #include <string.h>	 /* for bzero and string functions */
  #include <sys/stat.h>    /* for _fixpath */
  #include <unistd.h>	 /* for chdir, dup, dup2, etc. */
+ #include <dir.h>	 /* for getdisk */
  #if __DJGPP__ >= 2
  #include <fcntl.h>
  #include <io.h>		 /* for setmode */
***************
*** 4116,4121 ****
--- 4117,4132 ----
  
    errno = e;
    return 1;
+ }
+ 
+ char *
+ emacs_root_dir (void)
+ {
+   static char root_dir[4];
+ 
+   sprintf (root_dir, "%c:/", 'A' + getdisk ());
+   root_dir[0] = tolower (root_dir[0]);
+   return root_dir;
  }
  
  /* Remove all CR's that are followed by a LF.  */

Index: src/w32.c
===================================================================
RCS file: /cvs/emacs/src/w32.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -c -r1.68 -r1.69
*** src/w32.c	12 Oct 2001 03:26:20 -0000	1.68
--- src/w32.c	19 Dec 2001 18:56:44 -0000	1.69
***************
*** 875,880 ****
--- 875,895 ----
    init_user_info ();
  }
  
+ char *
+ emacs_root_dir (void)
+ {
+   static char root_dir[FILENAME_MAX];
+   const char *p;
+ 
+   p = getenv ("emacs_dir");
+   if (p == NULL)
+     abort ();
+   strcpy (root_dir, p);
+   root_dir[parse_root (root_dir, NULL)] = '\0';
+   dostounix_filename (root_dir);
+   return root_dir;
+ }
+ 
  /* We don't have scripts to automatically determine the system configuration
     for Emacs before it's compiled, and we don't want to have to make the
     user enter it, so we define EMACS_CONFIGURATION to invoke this runtime