From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 9DB66385841E; Wed, 1 Mar 2023 09:55:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DB66385841E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677664536; bh=yyL5Q6IdLl09xnzLBoyOmd4cp8CtYtdHvxh9E8Ir0MY=; h=From:To:Subject:Date:From; b=HUu+CWyw9GlwLskyf93d+GgxJpRounOpmq5cMQ+RMalfyfvruGJKrNqq9Yzv2CblG dtqgIu2OEiV5M/x3lN3pgFE3y8k15/tVLZp8FKbTJNAudJ4PayWqyjbv4aSfubiylz 9QgkEXNfwZQl7lrPs17dTBi2uS3vnPpCJpRAZDvQ= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Corinna Vinschen To: cygwin-cvs@sourceware.org Subject: [newlib-cygwin/main] Cygwin: mbsnrtowci: like mbsnrtowcs, just for wint_t X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 9870f1d1ffe36f77328c001fdf402c94f56c25ce X-Git-Newrev: 149cabea8220c7baf1185ccfaea03922bbfd390a Message-Id: <20230301095536.9DB66385841E@sourceware.org> Date: Wed, 1 Mar 2023 09:55:36 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D149cabea822= 0c7baf1185ccfaea03922bbfd390a commit 149cabea8220c7baf1185ccfaea03922bbfd390a Author: Corinna Vinschen AuthorDate: Wed Mar 1 10:44:52 2023 +0100 Commit: Corinna Vinschen CommitDate: Wed Mar 1 10:54:52 2023 +0100 Cygwin: mbsnrtowci: like mbsnrtowcs, just for wint_t =20 Deviation from standard: If the input is broken, the output will be broken. I. e., we just copy the current byte over into the wint_t destination and try to pick up on the next byte. This is in line with the way fnmatch works. =20 Signed-off-by: Corinna Vinschen Diff: --- winsup/cygwin/local_includes/wchar.h | 8 ++++++ winsup/cygwin/strfuncs.cc | 53 ++++++++++++++++++++++++++++++++= ++++ 2 files changed, 61 insertions(+) diff --git a/winsup/cygwin/local_includes/wchar.h b/winsup/cygwin/local_inc= ludes/wchar.h index d1b63859177e..ecf489cd588d 100644 --- a/winsup/cygwin/local_includes/wchar.h +++ b/winsup/cygwin/local_includes/wchar.h @@ -52,6 +52,14 @@ size_t wirtomb (char *, wint_t, mbstate_t *); a UTF-32 value. Defined in strfuncs.cc */ extern size_t mbrtowi (wint_t *, const char *, size_t, mbstate_t *); =20 +/* replacement function for mbsnrtowcs, returning a wint_t representing + a UTF-32 value. Defined in strfuncs.cc. + Deviation from standard: If the input is broken, the output will be + broken. I. e., we just copy the current byte over into the wint_t + destination and try to pick up on the next byte. This is in line + with the way fnmatch works. */ +extern size_t mbsnrtowci(wint_t *, const char **, size_t, size_t, mbstate_= t *); + /* convert wint_t string to char string, but *only* if the string consists entirely of ASCII chars */ static inline void diff --git a/winsup/cygwin/strfuncs.cc b/winsup/cygwin/strfuncs.cc index 80e3eb0ad6a8..9324e155319f 100644 --- a/winsup/cygwin/strfuncs.cc +++ b/winsup/cygwin/strfuncs.cc @@ -180,6 +180,59 @@ mbrtowi (wint_t *pwi, const char *s, size_t n, mbstate= _t *ps) return len; } =20 +extern "C" size_t +mbsnrtowci(wint_t *dst, const char **src, size_t nms, size_t len, mbstate_= t *ps) +{ + wint_t *ptr =3D dst; + const char *tmp_src; + size_t max; + size_t count =3D 0; + size_t bytes; + + if (dst =3D=3D NULL) + { + /* Ignore original len value and do not alter src pointer if the + dst pointer is NULL. */ + len =3D (size_t)-1; + tmp_src =3D *src; + src =3D &tmp_src; + } + max =3D len; + while (len > 0) + { + bytes =3D mbrtowi (ptr, *src, MB_CUR_MAX, ps); + if (bytes > 0) + { + *src +=3D bytes; + nms -=3D bytes; + ++count; + ptr =3D (dst =3D=3D NULL) ? NULL : ptr + 1; + --len; + } + else if (bytes =3D=3D 0) + { + *src =3D NULL; + return count; + } + else + { + /* Deviation from standard: If the input is broken, the output + will be broken. I. e., we just copy the current byte over + into the wint_t destination and try to pick up on the next + byte. This is in line with the way fnmatch works. */ + ps->__count =3D 0; + if (dst) + { + *ptr++ =3D (const wint_t) *(*src)++; + ++count; + --nms; + --len; + } + } + } + return (size_t) max; +} + /* The SJIS, JIS and eucJP conversion in newlib does not use UTF as wchar_t character representation. That's unfortunate for us since we require UTF for the OS. What we do here is to have our own