Cygwin: add wcipcpy and wcipncpy helper functions

wint_t replacements for wcpcpy and wcpncpy

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-03-01 10:36:09 +01:00
parent 77883ac914
commit b81969345d
2 changed files with 33 additions and 6 deletions

View File

@ -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 */

View File

@ -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