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: add wcipcpy and wcipncpy helper functions Date: Wed, 1 Mar 2023 09:55:26 +0000 (GMT) [thread overview] Message-ID: <20230301095526.8E3183858C54@sourceware.org> (raw) https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b81969345d807ec299d8afb3c55e27f732b7cb06 commit b81969345d807ec299d8afb3c55e27f732b7cb06 Author: Corinna Vinschen <corinna@vinschen.de> AuthorDate: Wed Mar 1 10:36:09 2023 +0100 Commit: Corinna Vinschen <corinna@vinschen.de> CommitDate: Wed Mar 1 10:54:52 2023 +0100 Cygwin: add wcipcpy and wcipncpy helper functions wint_t replacements for wcpcpy and wcpncpy Signed-off-by: Corinna Vinschen <corinna@vinschen.de> Diff: --- winsup/cygwin/glob.cc | 9 +++------ winsup/cygwin/local_includes/wchar.h | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/winsup/cygwin/glob.cc b/winsup/cygwin/glob.cc index 0b85a147acb7..dadc67e4c10a 100644 --- a/winsup/cygwin/glob.cc +++ b/winsup/cygwin/glob.cc @@ -203,13 +203,10 @@ check_classes_expr(const Char *&cptr, wint_t *classbuf = NULL, if (classbuf) { const Char *class_p = ctype + 1; size_t clen = cptr - class_p; - size_t idx; - if (clen < classbufsize) { - for (idx = 0; idx < clen; ++idx) - classbuf[idx] = CHAR(class_p[idx]); - classbuf[idx] = '\0'; - } else + if (clen < classbufsize) + *wcipncpy (classbuf, class_p, clen) = '\0'; + else ctype = NULL; } cptr++; /* Advance cptr to closing RBRACKET of class expr */ diff --git a/winsup/cygwin/local_includes/wchar.h b/winsup/cygwin/local_includes/wchar.h index b09d014c04df..125e49ece15c 100644 --- a/winsup/cygwin/local_includes/wchar.h +++ b/winsup/cygwin/local_includes/wchar.h @@ -101,6 +101,36 @@ wcincmp (const wint_t *s1, const wint_t *s2, size_t n) return (0); } +/* like wcpcpy, just for wint_t */ +static inline wint_t * +wcipcpy (wint_t *s1, const wint_t *s2) +{ + while ((*s1++ = *s2++)) + ; + return --s1; +} + +/* like wcpncpy, just for wint_t */ +static inline wint_t * +wcipncpy (wint_t *dst, const wint_t *src, size_t count) +{ + wint_t *ret = NULL; + + while (count > 0) + { + --count; + if ((*dst++ = *src++) == L'\0') + { + ret = dst - 1; + break; + } + } + while (count-- > 0) + *dst++ = L'\0'; + + return ret ? ret : dst; +} + #ifdef __cplusplus } #endif
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=20230301095526.8E3183858C54@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).