emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master 6e76e11: Fix regression in expand-file-name with dr


From: Eli Zaretskii
Subject: [Emacs-diffs] master 6e76e11: Fix regression in expand-file-name with drive-relative HOME
Date: Wed, 12 Dec 2018 11:28:19 -0500 (EST)

branch: master
commit 6e76e11c4200a4d4185e0b7d6cea5164d459737b
Author: Eli Zaretskii <address@hidden>
Commit: Eli Zaretskii <address@hidden>

    Fix regression in expand-file-name with drive-relative HOME
    
    * src/fileio.c (get_homedir) [DOS_NT]: Expand drive-relative
    $HOME to begin with "X:/".
    
    * test/src/fileio-tests.el (fileio-tests--relative-HOME): Add
    testing of drive-relative value of $HOME on MS-Windows and
    MS-DOS.
---
 src/fileio.c             | 28 ++++++++++++++++++++++++++++
 test/src/fileio-tests.el |  4 ++++
 2 files changed, 32 insertions(+)

diff --git a/src/fileio.c b/src/fileio.c
index d979571..687f6ec 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1692,6 +1692,34 @@ get_homedir (void)
       if (!home)
        return "";
     }
+#ifdef DOS_NT
+  /* If home is a drive-relative directory, expand it.  */
+  if (IS_DRIVE (*home)
+      && IS_DEVICE_SEP (home[1])
+      && !IS_DIRECTORY_SEP (home[2]))
+    {
+# ifdef WINDOWSNT
+      static char hdir[MAX_UTF8_PATH];
+# else
+      static char hdir[MAXPATHLEN];
+# endif
+      if (!getdefdir (c_toupper (*home) - 'A' + 1, hdir))
+       {
+         hdir[0] = c_toupper (*home);
+         hdir[1] = ':';
+         hdir[2] = '/';
+         hdir[3] = '\0';
+       }
+      if (home[2])
+       {
+         size_t homelen = strlen (hdir);
+         if (!IS_DIRECTORY_SEP (hdir[homelen - 1]))
+           strcat (hdir, "/");
+         strcat (hdir, home + 2);
+       }
+      home = hdir;
+    }
+#endif
   if (IS_ABSOLUTE_FILE_NAME (home))
     return home;
   if (!emacs_wd)
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index b7b78bb..a74bcea 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -102,4 +102,8 @@ Also check that an encoding error can appear in a symlink."
     (setenv "HOME" "a/b/c")
     (should (equal (expand-file-name "~/foo")
                    (expand-file-name "a/b/c/foo")))
+    (when (memq system-type '(ms-dos windows-nt))
+      ;; Test expansion of drive-relative file names.
+      (setenv "HOME" "x:foo")
+      (should (equal (expand-file-name "~/bar") "x:/foo/bar")))
     (setenv "HOME" old-home)))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]