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: fnmatch: convert wchar_t to wint_t
Date: Tue, 14 Feb 2023 12:10:03 +0000 (GMT)	[thread overview]
Message-ID: <20230214121003.C58B93858C30@sourceware.org> (raw)

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

commit 99da4956c5976770c1c1ce3d284c60c0cb5f1b57
Author:     Corinna Vinschen <corinna@vinschen.de>
AuthorDate: Tue Feb 14 12:47:54 2023 +0100
Commit:     Corinna Vinschen <corinna@vinschen.de>
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 <corinna@vinschen.de>

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	other threads:[~2023-02-14 12:10 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=20230214121003.C58B93858C30@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).