bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] canonicalize-lgpl: Canonicalize drive and dirsep too for MinGW.


From: Jan Nieuwenhuizen
Subject: [PATCH] canonicalize-lgpl: Canonicalize drive and dirsep too for MinGW.
Date: Fri, 10 Dec 2021 13:06:38 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)

Hello again!

So...it turns out that the bug report we got had nothing to do with the
file name casing after all, but was about '/' and '\\'; a somewhat
related issue though.

Currently, using CWD=~/.wine/drive_c/windows, calling
canonicalize_file_name on variations of "system.ini" gives three
trivially different results, one of which mixes '/' and '\\':

    system.ini:            => "C:\\windows/system.ini"
    ..\windows\system.ini: => "C:\\windows/system.ini"
    c:/windows/system.ini: => "c:/windows/system.ini"
    C:/windows/system.ini: => "C:/windows/system.ini"

The attached patch changes this to one, eh, "canonical" representation

   => "C:/windows/system.ini"

Of course, the first concern that you raised on my previous patch

    1) The 'realpath' function that canonicalize-lgpl.c implements is
       specified to return "an absolute pathname that resolves to the same
       directory entry, whose resolution does not involve '.', '..', or symbolic
       links." [1] There is no guarantee in the spec that it prefers lowercase,
       uppercase, or the case of the existing directory entry.

could still hold.  Otoh, the documentation does not say anything about
modifying or not modifying '/', this implementation is kind of cheap,
and it would be nice if we didn't have to do this in our client code
(thanks to your input on my previous patch, we discussed and decided not
to do case folding in our client code either).

WDYT?

Greetings,
Janneke

>From af7fd5d05ea79fe9badff54804644d1818552b1e Mon Sep 17 00:00:00 2001
From: "Jan (janneke) Nieuwenhuizen" <janneke@gnu.org>
Date: Fri, 10 Dec 2021 12:08:57 +0100
Subject: [PATCH] canonicalize-lgpl: Canonicalize drive and dirsep too for
 MinGW.
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=UTF-8

* lib/canonicalize-lgpl.c (realpath_stk)[__MINGW32__]: Return upper
case drive name and replace any '\\' with '/'.
---
 lib/canonicalize-lgpl.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c
index 92e9639720..ede3557b04 100644
--- a/lib/canonicalize-lgpl.c
+++ b/lib/canonicalize-lgpl.c
@@ -41,6 +41,10 @@
 #include <intprops.h>
 #include <scratch_buffer.h>
 
+#if __MINGW32__
+#include <ctype.h>
+#endif
+
 #ifdef _LIBC
 # include <shlib-compat.h>
 # define GCC_LINT 1
@@ -251,12 +255,25 @@ realpath_stk (const char *name, char *resolved,
             goto error_nomem;
           rname = rname_buf->data;
         }
+#if __MINGW32__
+      char *p = rname;
+      while (*p)
+        {
+          if (ISSLASH (*p))
+            *p = '/';
+          p++;
+        }
+#endif
       dest = __rawmemchr (rname, '\0');
       start = name;
       prefix_len = FILE_SYSTEM_PREFIX_LEN (rname);
     }
   else
     {
+#if __MINGW32__
+      if (HAS_DEVICE (rname))
+        rname[0] = toupper (rname[0]);
+#endif
       dest = __mempcpy (rname, name, prefix_len);
       *dest++ = '/';
       if (DOUBLE_SLASH_IS_DISTINCT_ROOT)
-- 
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond http://lilypond.org
Freelance IT http://JoyofSource.com | AvatarĀ® http://AvatarAcademy.com

reply via email to

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