From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2155) id 8E3183858C54; Wed, 1 Mar 2023 09:55:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8E3183858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677664526; bh=TgZ53pWK5yqq0KU6dcagPLF8r7mugqgGcSpE0Sv9XS8=; h=From:To:Subject:Date:From; b=RYxshcQXKQANZb7S9BX3zslRN6/QFxsoWrEaVNuGXcwqnBsiiAAIvfyyfh0VEpaGn HC68P8N1r0CyXr61IuTMWqCmikWI4sCSsgrk7yF3DzlA4tihxxSzgeoYcQ5hqJUiS5 qj//9U04BxJISHq6pLI84RpyJnQE+7QuVXKoVkJ0= 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: add wcipcpy and wcipncpy helper functions X-Act-Checkin: newlib-cygwin X-Git-Author: Corinna Vinschen X-Git-Refname: refs/heads/main X-Git-Oldrev: 77883ac914939e3fd5b3001b78857a3d11942104 X-Git-Newrev: b81969345d807ec299d8afb3c55e27f732b7cb06 Message-Id: <20230301095526.8E3183858C54@sourceware.org> Date: Wed, 1 Mar 2023 09:55:26 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3Db81969345d8= 07ec299d8afb3c55e27f732b7cb06 commit b81969345d807ec299d8afb3c55e27f732b7cb06 Author: Corinna Vinschen AuthorDate: Wed Mar 1 10:36:09 2023 +0100 Commit: Corinna Vinschen CommitDate: Wed Mar 1 10:54:52 2023 +0100 Cygwin: add wcipcpy and wcipncpy helper functions =20 wint_t replacements for wcpcpy and wcpncpy =20 Signed-off-by: Corinna Vinschen 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 *classbu= f =3D NULL, if (classbuf) { const Char *class_p =3D ctype + 1; size_t clen =3D cptr - class_p; - size_t idx; =20 - if (clen < classbufsize) { - for (idx =3D 0; idx < clen; ++idx) - classbuf[idx] =3D CHAR(class_p[idx]); - classbuf[idx] =3D '\0'; - } else + if (clen < classbufsize) + *wcipncpy (classbuf, class_p, clen) =3D '\0'; + else ctype =3D NULL; } cptr++; /* Advance cptr to closing RBRACKET of class expr */ diff --git a/winsup/cygwin/local_includes/wchar.h b/winsup/cygwin/local_inc= ludes/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); } =20 +/* like wcpcpy, just for wint_t */ +static inline wint_t * +wcipcpy (wint_t *s1, const wint_t *s2) +{ + while ((*s1++ =3D *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 =3D NULL; + + while (count > 0) + { + --count; + if ((*dst++ =3D *src++) =3D=3D L'\0') + { + ret =3D dst - 1; + break; + } + } + while (count-- > 0) + *dst++ =3D L'\0'; + + return ret ? ret : dst; +} + #ifdef __cplusplus } #endif