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

commit 99da4956c5976770c1c1ce3d284c60c0cb5f1b57
Author:     Corinna Vinschen <[email protected]>
AuthorDate: Tue Feb 14 12:47:54 2023 +0100
Commit:     Corinna Vinschen <[email protected]>
CommitDate: Tue Feb 14 12:48:31 2023 +0100

    Cygwin: fnmatch: convert wchar_t to wint_t
    
    ...thus handling all Unicode values sanely.
    
    Signed-off-by: Corinna Vinschen <[email protected]>

Diff:
---
 winsup/cygwin/libc/fnmatch.c | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/winsup/cygwin/libc/fnmatch.c b/winsup/cygwin/libc/fnmatch.c
index 410254ab86f8..06732426b9c4 100644
--- a/winsup/cygwin/libc/fnmatch.c
+++ b/winsup/cygwin/libc/fnmatch.c
@@ -52,7 +52,7 @@ __FBSDID("$FreeBSD: head/lib/libc/gen/fnmatch.c 288309 
2015-09-27 12:52:18Z jill
  * 1. Patterns with illegal byte sequences match nothing.
  * 2. Illegal byte sequences in the "string" argument are handled by treating
  *    them as single-byte characters with a value of the first byte of the
- *    sequence cast to wchar_t.
+ *    sequence cast to wint_t.
  * 3. Multibyte conversion state objects (mbstate_t) are passed around and
  *    used for most, but not all, conversions. Further work will be required
  *    to support state-dependent encodings.
@@ -72,7 +72,7 @@ __FBSDID("$FreeBSD: head/lib/libc/gen/fnmatch.c 288309 
2015-09-27 12:52:18Z jill
 #define RANGE_NOMATCH   0
 #define RANGE_ERROR     (-1)
 
-static int rangematch(const char *, wchar_t, int, char **, mbstate_t *);
+static int rangematch(const char *, wint_t, int, char **, mbstate_t *);
 static int fnmatch1(const char *, const char *, const char *, int, mbstate_t,
                mbstate_t);
 
@@ -92,16 +92,16 @@ fnmatch1(const char *pattern, const char *string, const 
char *stringstart,
        mbstate_t bt_patmbs, bt_strmbs;
        char *newp;
        char c;
-       wchar_t pc, sc;
+       wint_t pc, sc;
        size_t pclen, sclen;
 
        bt_pattern = bt_string = NULL;
        for (;;) {
-               pclen = mbrtowc(&pc, pattern, MB_LEN_MAX, &patmbs);
+               pclen = mbrtowi(&pc, pattern, MB_LEN_MAX, &patmbs);
                if (pclen == (size_t)-1 || pclen == (size_t)-2)
                        return (FNM_NOMATCH);
                pattern += pclen;
-               sclen = mbrtowc(&sc, string, MB_LEN_MAX, &strmbs);
+               sclen = mbrtowi(&sc, string, MB_LEN_MAX, &strmbs);
                if (sclen == (size_t)-1 || sclen == (size_t)-2) {
                        sc = (unsigned char)*string;
                        sclen = 1;
@@ -183,7 +183,7 @@ fnmatch1(const char *pattern, const char *string, const 
char *stringstart,
                        break;
                case '\\':
                        if (!(flags & FNM_NOESCAPE)) {
-                               pclen = mbrtowc(&pc, pattern, MB_LEN_MAX,
+                               pclen = mbrtowi(&pc, pattern, MB_LEN_MAX,
                                    &patmbs);
                                if (pclen == (size_t)-1 || pclen == (size_t)-2)
                                        return (FNM_NOMATCH);
@@ -208,7 +208,7 @@ fnmatch1(const char *pattern, const char *string, const 
char *stringstart,
                                 */
                                if (bt_pattern == NULL)
                                        return (FNM_NOMATCH);
-                               sclen = mbrtowc(&sc, bt_string, MB_LEN_MAX,
+                               sclen = mbrtowi(&sc, bt_string, MB_LEN_MAX,
                                    &bt_strmbs);
                                if (sclen == (size_t)-1 ||
                                    sclen == (size_t)-2) {
@@ -232,11 +232,11 @@ fnmatch1(const char *pattern, const char *string, const 
char *stringstart,
 }
 
 static int
-rangematch(const char *pattern, wchar_t test, int flags, char **newp,
+rangematch(const char *pattern, wint_t test, int flags, char **newp,
     mbstate_t *patmbs)
 {
        int negate, ok;
-       wchar_t c, c2;
+       wint_t c, c2;
        size_t pclen;
        const char *origpat;
 #ifndef __CYGWIN__
@@ -274,7 +274,7 @@ rangematch(const char *pattern, wchar_t test, int flags, 
char **newp,
                        return (RANGE_NOMATCH);
                } else if (*pattern == '\\' && !(flags & FNM_NOESCAPE))
                        pattern++;
-               pclen = mbrtowc(&c, pattern, MB_LEN_MAX, patmbs);
+               pclen = mbrtowi(&c, pattern, MB_LEN_MAX, patmbs);
                if (pclen == (size_t)-1 || pclen == (size_t)-2)
                        return (RANGE_NOMATCH);
                pattern += pclen;
@@ -287,7 +287,7 @@ rangematch(const char *pattern, wchar_t test, int flags, 
char **newp,
                        if (*++pattern == '\\' && !(flags & FNM_NOESCAPE))
                                if (*pattern != EOS)
                                        pattern++;
-                       pclen = mbrtowc(&c2, pattern, MB_LEN_MAX, patmbs);
+                       pclen = mbrtowi(&c2, pattern, MB_LEN_MAX, patmbs);
                        if (pclen == (size_t)-1 || pclen == (size_t)-2)
                                return (RANGE_NOMATCH);
                        pattern += pclen;

Reply via email to