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

commit a51147467e6cf58618433286f93d17043e00b0fc
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Wed Feb 22 10:47:54 2023 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Wed Feb 22 10:47:54 2023 +0100

    Cygwin: glob: perform ignore_case_with_glob on input
    
    Rather than converting single chars on the fly to lowercase
    in case ignore_case_with_glob is set, perform the conversion
    on the entire input (pattern and filenames).

Diff:
---
 winsup/cygwin/glob.cc | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc
index 2f86e46985d7..64c3507d891e 100644
--- a/winsup/cygwin/glob.cc
+++ b/winsup/cygwin/glob.cc
@@ -95,8 +95,9 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 2010/05/12 
17:44:00 gordon Ex
 #include "collate.h"
 
 #ifdef __CYGWIN__
-#define CCHAR(c)       (ignore_case_with_glob ? towlower (CHAR (c)) : CHAR (c))
 #define Cchar(c)       (ignore_case_with_glob ? towlower (c) : (c))
+#else
+#define Cchar(c)       (c)
 #endif
 
 #undef MAXPATHLEN
@@ -122,6 +123,7 @@ __FBSDID("$FreeBSD: src/lib/libc/gen/glob.c,v 1.28 
2010/05/12 17:44:00 gordon Ex
 #define        SLASH           '/'
 #define        COMMA           ','
 
+#undef DEBUG /* never define */
 #ifndef DEBUG
 
 #define        M_QUOTE         0x40000000U
@@ -252,7 +254,7 @@ glob(const char *__restrict pattern, int flags, int 
(*errfunc)(const char *, int
                                return (GLOB_NOMATCH);
                        else if (clen == 0)
                                break;
-                       *bufnext++ = wc;
+                       *bufnext++ = Cchar(wc);
                        patnext += clen;
                }
        } else {
@@ -272,7 +274,7 @@ glob(const char *__restrict pattern, int flags, int 
(*errfunc)(const char *, int
                                return (GLOB_NOMATCH);
                        else if (clen == 0)
                                break;
-                       *bufnext++ = wc | prot;
+                       *bufnext++ = Cchar(wc) | prot;
                        patnext += clen;
                }
        }
@@ -779,6 +781,19 @@ glob3(Char *pathbuf, Char *pathend, Char *pathend_last,
                                break;
                        sc += clen;
                }
+#ifdef __CYGWIN__
+               if (ignore_case_with_glob) {
+                       wint_t lower_path[MAXPATHLEN];
+                       wint_t *lp = lower_path, *sp = pathend;
+
+                       while ((*lp++ = towlower(*sp++)))
+                               ;
+                       if (!match(lower_path, pattern, restpattern)) {
+                               *pathend = EOS;
+                               continue;
+                       }
+               } else
+#endif
                if (!match(pathend, pattern, restpattern)) {
                        *pathend = EOS;
                        continue;
@@ -932,7 +947,7 @@ match(Char *name, Char *pat, Char *patend)
                                return(0);
                        break;
                default:
-                       if (Cchar(*name++) != Cchar(*c))
+                       if (*name++ != *c)
                                return(0);
                        break;
                }

Reply via email to