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: mbsnrtowci: like mbsnrtowcs, just for wint_t Date: Wed, 1 Mar 2023 09:55:36 +0000 (GMT) [thread overview] Message-ID: <20230301095536.9DB66385841E@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=149cabea8220c7baf1185ccfaea03922bbfd390a commit 149cabea8220c7baf1185ccfaea03922bbfd390a Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Wed Mar 1 10:44:52 2023 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Wed Mar 1 10:54:52 2023 +0100 Cygwin: mbsnrtowci: like mbsnrtowcs, just for wint_t 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. Signed-off-by: Corinna Vinschen <corinna@vinschen.de> 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_includes/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 *); +/* 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; } +extern "C" size_t +mbsnrtowci(wint_t *dst, const char **src, size_t nms, size_t len, mbstate_t *ps) +{ + wint_t *ptr = dst; + const char *tmp_src; + size_t max; + size_t count = 0; + size_t bytes; + + if (dst == NULL) + { + /* Ignore original len value and do not alter src pointer if the + dst pointer is NULL. */ + len = (size_t)-1; + tmp_src = *src; + src = &tmp_src; + } + max = len; + while (len > 0) + { + bytes = mbrtowi (ptr, *src, MB_CUR_MAX, ps); + if (bytes > 0) + { + *src += bytes; + nms -= bytes; + ++count; + ptr = (dst == NULL) ? NULL : ptr + 1; + --len; + } + else if (bytes == 0) + { + *src = 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 = 0; + if (dst) + { + *ptr++ = (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
reply other threads:[~2023-03-01 9:55 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=20230301095536.9DB66385841E@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: linkBe 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).