public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Corinna Vinschen <corinna@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin/main] Cygwin: __wscollate_range_cmp: workaround wcscoll's case-insensitivity
Date: Wed, 22 Feb 2023 11:21:24 +0000 (GMT)	[thread overview]
Message-ID: <20230222112124.BCF5D385840F@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=2229f42400b992669a99cba9b42b600b0ba01b7f

commit 2229f42400b992669a99cba9b42b600b0ba01b7f
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Wed Feb 22 12:20:32 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Wed Feb 22 12:20:32 2023 +0100

    Cygwin: __wscollate_range_cmp: workaround wcscoll's case-insensitivity
    
    Most locales using latin characters ignore case while sorting.
    This is what wcscoll does (correctly so).  However, there's an
    internal order of collating sequences compared to the base
    character, which is case-sensitive, at least in GLibc.
    
    There's no way to express this in Windows, because CompareString
    and LCMapString *always* use case-insensitivity in those locales,
    even if none of the *IGNORECASE sorting flags are used.
    
    We want to follow glibc's behaviour more closely, so we add an
    extra check for the case and make sure upper and lower cased
    letters don't comapre as identical.
    
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

Diff:
---
 winsup/cygwin/nlsfuncs.cc | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/winsup/cygwin/nlsfuncs.cc b/winsup/cygwin/nlsfuncs.cc
index eb9948dd37fc..543f20e4437b 100644
--- a/winsup/cygwin/nlsfuncs.cc
+++ b/winsup/cygwin/nlsfuncs.cc
@@ -1206,6 +1206,12 @@ __wscollate_range_cmp (wint_t *c1, wint_t *c2,
   wchar_t s1[c1len * 2 + 1] = { 0 };	/* # of chars if all are surrogates */
   wchar_t s2[c2len * 2 + 1] = { 0 };
 
+  /* wcscoll() ignores case in many locales. but we don't want that
+     for filenames... */
+  if ((iswupper (*c1) && !iswupper (*c2))
+      || (iswlower (*c1) && !iswlower (*c2)))
+    return *c1 - *c2;
+
   wcintowcs (s1, c1, c1len);
   wcintowcs (s2, c2, c2len);
   return wcscoll_l (s1, s2, __get_current_locale ());

                 reply	other threads:[~2023-02-22 11:21 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230222112124.BCF5D385840F@sourceware.org \
    --to=corinna@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).