Implement few wide char functions.

This commit is contained in:
Sebastian Bauer 2018-03-28 17:09:18 +02:00
parent 846eebc66c
commit 6f3b3b6d28
14 changed files with 59 additions and 28 deletions

View File

@ -40,6 +40,6 @@
int
wcscmp(const wchar_t *s1, const wchar_t * s2)
{
/* ZZZ unimplemented */
return(0);
for (; *s1==*s2 && *s1 && *s2; s1++, s2++);
return *s1 - *s2;
}

View File

@ -40,6 +40,7 @@
wchar_t *
wcscpy(wchar_t *dest, const wchar_t *src)
{
/* ZZZ unimplemented */
return(NULL);
wchar_t *a = dest;
while ((*dest++ = *src++));
return a;
}

View File

@ -37,9 +37,12 @@
/****************************************************************************/
/* Implementation based on musl */
size_t
wcslen(const wchar_t *s)
{
/* ZZZ unimplemented */
return(0);
const wchar_t *a;
for (a=s; *s; s++);
return s-a;
}

View File

@ -37,9 +37,14 @@
/****************************************************************************/
/* Implementation based on musl */
wchar_t *
wcsncat(wchar_t *dest, const wchar_t *src, size_t n)
{
/* ZZZ unimplemented */
return(NULL);
wchar_t *a = dest;
dest += wcslen(dest);
while (n && *src) n--, *dest++ = *src++;
*dest++ = 0;
return a;
}

View File

@ -40,6 +40,6 @@
int
wctob(wint_t c)
{
/* ZZZ unimplemented */
return(0);
if (c < 128U) return c;
return EOF;
}

View File

@ -37,9 +37,11 @@
/****************************************************************************/
/* Implementation based on musl */
wchar_t *
wmemchr(const wchar_t *ptr, wchar_t val, size_t len)
{
/* ZZZ unimplemented */
return(NULL);
for (; len && *ptr != val; len--, ptr++);
return len ? (wchar_t *)ptr : 0;
}

View File

@ -37,9 +37,11 @@
/****************************************************************************/
/* Implementation based on musl */
int
wmemcmp(const wchar_t *ptr1, const wchar_t *ptr2, size_t len)
{
/* ZZZ unimplemented */
return(0);
for (; len && *ptr1==*ptr2; len--, ptr1++, ptr2++);
return len ? *ptr1-*ptr2 : 0;
}

View File

@ -37,9 +37,12 @@
/****************************************************************************/
/* Implementation based on musl */
wchar_t *
wmemcpy(wchar_t *dest, const wchar_t *src, size_t len)
{
/* ZZZ unimplemented */
return(NULL);
wchar_t *a = dest;
while (len--) *dest++ = *src++;
return a;
}

View File

@ -37,9 +37,15 @@
/****************************************************************************/
/* Implementation based on musl */
wchar_t *
wmemmove(wchar_t *dest, const wchar_t * src, size_t len)
{
/* ZZZ unimplemented */
return(NULL);
wchar_t *d0 = dest;
if ((size_t)(dest-src) < len)
while (len--) dest[len] = src[len];
else
while (len--) *dest++ = *src++;
return d0;
}

View File

@ -37,9 +37,12 @@
/****************************************************************************/
/* Implementation based on musl */
wchar_t *
wmemset(wchar_t *ptr, int val, size_t len)
{
/* ZZZ unimplemented */
return(NULL);
wchar_t *ret = ptr;
while (len--) *ptr++ = val;
return ret;
}

View File

@ -37,9 +37,10 @@
/****************************************************************************/
/* Implementation based on musl */
int
iswalnum(wint_t c)
{
/* ZZZ unimplemented */
return(0);
return iswdigit(c) || iswalpha(c);
}

View File

@ -35,11 +35,12 @@
#include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/
int
iswalpha(wint_t c)
{
/* ZZZ unimplemented */
return(0);
return isalpha(c);
}

View File

@ -35,11 +35,14 @@
#include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/
/* Implementation based on musl */
int
iswblank(wint_t c)
{
/* ZZZ unimplemented */
return(0);
return isblank(c);
}

View File

@ -35,11 +35,12 @@
#include <wctype.h>
#endif /* _WCTYPE_HEADERS_H */
#include <ctype.h>
/****************************************************************************/
int
iswdigit(wint_t c)
{
/* ZZZ unimplemented */
return(0);
return isdigit(c);
}