diff --git a/include/wchar.h b/include/wchar.h index 87e244a33721ffb4d45e22be878ef6a9b4fd82c9..12ddd4f49a632cc7a5b7bace935258a522be9615 100644 --- a/include/wchar.h +++ b/include/wchar.h @@ -11,6 +11,11 @@ extern "C" { #define __NEED_wchar_t #define __NEED_wint_t +#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ + || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) +#define __NEED_locale_t +#endif + #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) #define __NEED_wctype_t #endif @@ -132,6 +137,16 @@ size_t wcsftime (wchar_t *, size_t, const wchar_t *, const struct tm *); FILE *open_wmemstream(wchar_t **, size_t *); size_t mbsnrtowcs(wchar_t *, const char **, size_t, size_t, mbstate_t *); size_t wcsnrtombs(char *, const wchar_t **, size_t, size_t, mbstate_t *); +wchar_t *wcsdup(const wchar_t *); +size_t wcsnlen (const wchar_t *, size_t); +wchar_t *wcpcpy (wchar_t *, const wchar_t *); +wchar_t *wcpncpy (wchar_t *, const wchar_t *, size_t); +int wcscasecmp(const wchar_t *, const wchar_t *); +int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); +int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); +int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); +int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); +size_t wcsxfrm_l(wchar_t *, const wchar_t *, size_t n, locale_t); #endif #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) diff --git a/src/locale/wcscoll_l.c b/src/locale/wcscoll_l.c new file mode 100644 index 0000000000000000000000000000000000000000..f257ec8d98002c81ccc40293dca7cefb565849f0 --- /dev/null +++ b/src/locale/wcscoll_l.c @@ -0,0 +1,6 @@ +#include + +int wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale) +{ + return wcscoll(l, r); +} diff --git a/src/locale/wcsxfrm_l.c b/src/locale/wcsxfrm_l.c new file mode 100644 index 0000000000000000000000000000000000000000..831998e91c9657eec424f10476ef736a83187d84 --- /dev/null +++ b/src/locale/wcsxfrm_l.c @@ -0,0 +1,6 @@ +#include + +size_t wcsxfrm_l(wchar_t *dest, const wchar_t *src, size_t n, locale_t locale) +{ + return wcsxfrm(dest, src, n); +} diff --git a/src/string/wcpcpy.c b/src/string/wcpcpy.c new file mode 100644 index 0000000000000000000000000000000000000000..fdf878f64cf8ea57fa362a93329f4d8764ac6572 --- /dev/null +++ b/src/string/wcpcpy.c @@ -0,0 +1,6 @@ +#include + +wchar_t *wcpcpy(wchar_t *d, const wchar_t *s) +{ + return wcscpy(d, s) + wcslen(s); +} diff --git a/src/string/wcpncpy.c b/src/string/wcpncpy.c new file mode 100644 index 0000000000000000000000000000000000000000..aef8096237cd7db0bacb8b47d8daf85c5bd9bf88 --- /dev/null +++ b/src/string/wcpncpy.c @@ -0,0 +1,6 @@ +#include + +wchar_t *wcpncpy(wchar_t *d, const wchar_t *s, size_t n) +{ + return wcsncpy(d, s, n) + wcsnlen(s, n); +} diff --git a/src/string/wcscasecmp.c b/src/string/wcscasecmp.c new file mode 100644 index 0000000000000000000000000000000000000000..3edeec7d3dd632fd1241b6d246bbc4abb2098672 --- /dev/null +++ b/src/string/wcscasecmp.c @@ -0,0 +1,7 @@ +#include +#include + +int wcscasecmp(const wchar_t *l, const wchar_t *r) +{ + return wcsncasecmp(l, r, -1); +} diff --git a/src/string/wcscasecmp_l.c b/src/string/wcscasecmp_l.c new file mode 100644 index 0000000000000000000000000000000000000000..065dd0aad757de3b9f1352dce7f04d439e39e9a7 --- /dev/null +++ b/src/string/wcscasecmp_l.c @@ -0,0 +1,6 @@ +#include + +int wcscasecmp_l(const wchar_t *l, const wchar_t *r, locale_t locale) +{ + return wcscasecmp(l, r); +} diff --git a/src/string/wcsdup.c b/src/string/wcsdup.c new file mode 100644 index 0000000000000000000000000000000000000000..dd49c1b6297f695d7aea4fd4c8f586b2dff0c5da --- /dev/null +++ b/src/string/wcsdup.c @@ -0,0 +1,11 @@ +#include +#include +#include "libc.h" + +wchar_t *wcsdup(const wchar_t *s) +{ + size_t l = wcslen(s); + wchar_t *d = malloc((l+1)*sizeof(wchar_t)); + if (!d) return NULL; + return wmemcpy(d, s, l+1); +} diff --git a/src/string/wcsncasecmp.c b/src/string/wcsncasecmp.c new file mode 100644 index 0000000000000000000000000000000000000000..8fefe799c4370312f7539cc7a2e24016d9b7f546 --- /dev/null +++ b/src/string/wcsncasecmp.c @@ -0,0 +1,9 @@ +#include +#include + +int wcsncasecmp(const wchar_t *l, const wchar_t *r, size_t n) +{ + if (!n--) return 0; + for (; *l && *r && n && (*l == *r || towlower(*l) == towlower(*r)); l++, r++, n--); + return towlower(*l) - towlower(*r); +} diff --git a/src/string/wcsncasecmp_l.c b/src/string/wcsncasecmp_l.c new file mode 100644 index 0000000000000000000000000000000000000000..63872481927b40bc7abf85c0232d15b3786bfad7 --- /dev/null +++ b/src/string/wcsncasecmp_l.c @@ -0,0 +1,6 @@ +#include + +int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale) +{ + return wcsncasecmp(l, r, n); +} diff --git a/src/string/wcsnlen.c b/src/string/wcsnlen.c new file mode 100644 index 0000000000000000000000000000000000000000..a7763373147b4fa1215a74cf20952630276b9e9a --- /dev/null +++ b/src/string/wcsnlen.c @@ -0,0 +1,8 @@ +#include + +size_t wcsnlen(const wchar_t *s, size_t n) +{ + const wchar_t *z = wmemchr(s, 0, n); + if (z) n = z-s; + return n; +} diff --git a/src/string/wcstok.c b/src/string/wcstok.c new file mode 100644 index 0000000000000000000000000000000000000000..c932d0a06d62c935be0d1da2f0dbc66ac5a98d36 --- /dev/null +++ b/src/string/wcstok.c @@ -0,0 +1,12 @@ +#include + +wchar_t *wcstok(wchar_t *s, const wchar_t *sep, wchar_t **p) +{ + if (!s && !(s = *p)) return NULL; + s += wcsspn(s, sep); + if (!*s) return *p = 0; + *p = s + wcscspn(s, sep); + if (**p) *(*p)++ = 0; + else *p = 0; + return s; +}