From f6f0082a0ea44bc3bd722a646f7eae8088e5d293 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 19:56:45 +0200 Subject: [PATCH 01/18] Include sys/clib2_stdc.h for restrict. --- library/include/wchar.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/include/wchar.h b/library/include/wchar.h index ddcbbac..cacc593 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -43,6 +43,10 @@ /****************************************************************************/ +#ifndef _SYS_CLIB2_STDC_H +#include +#endif /* _SYS_CLIB2_STDC_H */ + #ifndef _STDDEF_H #include #endif /* _STDDEF_H */ From f5f0e17e784ffe577f5f4c73613c8b32fcd3842b Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 19:59:23 +0200 Subject: [PATCH 02/18] Define ISO 99 multibyte functions also in C++ context. --- library/include/wchar.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/include/wchar.h b/library/include/wchar.h index cacc593..3dce6f1 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -181,7 +181,7 @@ extern size_t wcsftime(wchar_t *s, size_t maxsize, const wchar_t *format, const /****************************************************************************/ -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +#if (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || defined(__cplusplus) extern size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict ps); extern size_t mbrtowc(wchar_t *restrict pwc, const char *restrict s, size_t n, mbstate_t *restrict ps); From 391e7e39ad505c79d1c2991214dc15c097c5b154 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 19:59:54 +0200 Subject: [PATCH 03/18] Add wcscoll() prototype. --- library/include/wchar.h | 1 + 1 file changed, 1 insertion(+) diff --git a/library/include/wchar.h b/library/include/wchar.h index 3dce6f1..e27b055 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -190,6 +190,7 @@ extern size_t mbsnrtowcs(wchar_t *restrict dst, const char **restrict src, size_ extern size_t mbsrtowcs(wchar_t *restrict dst, const char **restrict src, size_t len, mbstate_t *restrict ps); extern size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps); +extern int wcscoll(const wchar_t *ws1, const wchar_t *ws2); extern int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t loc); extern size_t wcscspn(const wchar_t *ws1, const wchar_t *ws2); extern size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict src, size_t nwc, size_t len, mbstate_t *restrict ps); From 5733c99ba1b56408b24db331457a7a51209f6c74 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 20:00:28 +0200 Subject: [PATCH 04/18] Fix wcspbrk() definition to match the prototype. --- library/wchar_wcspbrk.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/wchar_wcspbrk.c b/library/wchar_wcspbrk.c index 75bd74a..83897a4 100644 --- a/library/wchar_wcspbrk.c +++ b/library/wchar_wcspbrk.c @@ -37,7 +37,7 @@ /****************************************************************************/ -wchar_t +wchar_t * wcspbrk(const wchar_t *s, const wchar_t *set) { /* ZZZ unimplemented */ From 456123fe7f293ef2b0527b7971e1dbdcb7ee1e5f Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 20:02:54 +0200 Subject: [PATCH 05/18] Add dummy wctob(). --- library/wchar_wctob.c | 45 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 library/wchar_wctob.c diff --git a/library/wchar_wctob.c b/library/wchar_wctob.c new file mode 100644 index 0000000..de9a668 --- /dev/null +++ b/library/wchar_wctob.c @@ -0,0 +1,45 @@ +/* + * $Id: wchar_wmemchr.c,v 1.3 2006-01-08 12:04:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2015 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +int +wctob(wint_t c) +{ + /* ZZZ unimplemented */ + return(0); +} From 75d47ccdade9d454f4c12a2fe422a9e12eb6cc0d Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 27 Mar 2018 20:03:45 +0200 Subject: [PATCH 06/18] Build all existing wchar and wctype functions. --- library/libc.gmk | 70 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/library/libc.gmk b/library/libc.gmk index 1a8cddd..746af4d 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -374,7 +374,75 @@ C_LIB := \ unistd_unlink.o \ unistd_usleep.o \ utime_utime.o \ - utsname_uname.o + utsname_uname.o \ + wchar_btowc.o \ + wchar_fgetwc.o \ + wchar_fgetws.o \ + wchar_fputwc.o \ + wchar_fputws.o \ + wchar_fwide.o \ + wchar_fwprintf.o \ + wchar_fwscanf.o \ + wchar_getwc.o \ + wchar_getwchar.o \ + wchar_mbrlen.o \ + wchar_mbsinit.o \ + wchar_mbsrtowcs.o \ + wchar_putwc.o \ + wchar_putwchar.o \ + wchar_swprintf.o \ + wchar_swscanf.o \ + wchar_ungetwc.o \ + wchar_vfwprintf.o \ + wchar_vswprintf.o \ + wchar_vwprintf.o \ + wchar_wcrtomb.o \ + wchar_wcscat.o \ + wchar_wcschr.o \ + wchar_wcscmp.o \ + wchar_wcscpy.o \ + wchar_wcsftime.o \ + wchar_wcslen.o \ + wchar_wcsncat.o \ + wchar_wcsncmp.o \ + wchar_wcsncpy.o \ + wchar_wcspbrk.o \ + wchar_wcsrtombs.o \ + wchar_wcsspn.o \ + wchar_wcstod.o \ + wchar_wcstok.o \ + wchar_wcstol.o \ + wchar_wcstoll.o \ + wchar_wcstoul.o \ + wchar_wcstoull.o \ + wchar_wcsxfrm.o \ + wchar_wctob.o \ + wchar_wmemchr.o \ + wchar_wmemcmp.o \ + wchar_wmemcpy.o \ + wchar_wmemmove.o \ + wchar_wmemset.o \ + wchar_wprintf.o \ + wchar_wscanf.o \ + wchar_wscoll.o \ + wctype_iswalnum.o \ + wctype_iswalpha.o \ + wctype_iswblank.o \ + wctype_iswcntrl.o \ + wctype_iswctype.o \ + wctype_iswdigit.o \ + wctype_iswgraph.o \ + wctype_iswlower.o \ + wctype_iswprint.o \ + wctype_iswpunc.o \ + wctype_iswspace.o \ + wctype_iswupper.o \ + wctype_iswxdigit.o \ + wctype_towctrans.o \ + wctype_towlower.o \ + wctype_towupper.o \ + wctype_wctrans.o \ + wctype_wctype.o ############################################################################## From 846eebc66cacc33e1f0540d5032264026542b595 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Wed, 28 Mar 2018 17:08:42 +0200 Subject: [PATCH 07/18] Fix mbtowc() to and compile it. --- library/libc.gmk | 1 + library/stdlib_mbtowc.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/library/libc.gmk b/library/libc.gmk index 746af4d..63707e5 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -234,6 +234,7 @@ C_LIB := \ stdlib_main_stub.o \ stdlib_malloc.o \ stdlib_math.o \ + stdlib_mbtowc.o \ stdlib_mkdtemp.o \ stdlib_mkstemp.o \ stdlib_mktemp.o \ diff --git a/library/stdlib_mbtowc.c b/library/stdlib_mbtowc.c index 0d592a6..9db5ee6 100644 --- a/library/stdlib_mbtowc.c +++ b/library/stdlib_mbtowc.c @@ -37,13 +37,13 @@ /****************************************************************************/ -#if defined(defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n) { - /* ZZZ unimplemented */ - return(-1); + errno = EILSEQ; + return -1; } #endif From 6f3b3b6d28df37b9160595deeda2237b407d0324 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Wed, 28 Mar 2018 17:09:18 +0200 Subject: [PATCH 08/18] Implement few wide char functions. --- library/wchar_wcscmp.c | 4 ++-- library/wchar_wcscpy.c | 5 +++-- library/wchar_wcslen.c | 7 +++++-- library/wchar_wcsncat.c | 9 +++++++-- library/wchar_wctob.c | 4 ++-- library/wchar_wmemchr.c | 6 ++++-- library/wchar_wmemcmp.c | 6 ++++-- library/wchar_wmemcpy.c | 7 +++++-- library/wchar_wmemmove.c | 10 ++++++++-- library/wchar_wmemset.c | 7 +++++-- library/wctype_iswalnum.c | 5 +++-- library/wctype_iswalpha.c | 5 +++-- library/wctype_iswblank.c | 7 +++++-- library/wctype_iswdigit.c | 5 +++-- 14 files changed, 59 insertions(+), 28 deletions(-) diff --git a/library/wchar_wcscmp.c b/library/wchar_wcscmp.c index 0c8103d..c12ff67 100644 --- a/library/wchar_wcscmp.c +++ b/library/wchar_wcscmp.c @@ -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; } diff --git a/library/wchar_wcscpy.c b/library/wchar_wcscpy.c index 94b2ad9..d71fa25 100644 --- a/library/wchar_wcscpy.c +++ b/library/wchar_wcscpy.c @@ -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; } diff --git a/library/wchar_wcslen.c b/library/wchar_wcslen.c index 9ecc861..cc7393a 100644 --- a/library/wchar_wcslen.c +++ b/library/wchar_wcslen.c @@ -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; } diff --git a/library/wchar_wcsncat.c b/library/wchar_wcsncat.c index 3155dc0..c993592 100644 --- a/library/wchar_wcsncat.c +++ b/library/wchar_wcsncat.c @@ -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; } diff --git a/library/wchar_wctob.c b/library/wchar_wctob.c index de9a668..704d657 100644 --- a/library/wchar_wctob.c +++ b/library/wchar_wctob.c @@ -40,6 +40,6 @@ int wctob(wint_t c) { - /* ZZZ unimplemented */ - return(0); + if (c < 128U) return c; + return EOF; } diff --git a/library/wchar_wmemchr.c b/library/wchar_wmemchr.c index 840911b..003a40c 100644 --- a/library/wchar_wmemchr.c +++ b/library/wchar_wmemchr.c @@ -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; } diff --git a/library/wchar_wmemcmp.c b/library/wchar_wmemcmp.c index b43fe93..454f348 100644 --- a/library/wchar_wmemcmp.c +++ b/library/wchar_wmemcmp.c @@ -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; } diff --git a/library/wchar_wmemcpy.c b/library/wchar_wmemcpy.c index 230b7c3..95f1b36 100644 --- a/library/wchar_wmemcpy.c +++ b/library/wchar_wmemcpy.c @@ -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; } diff --git a/library/wchar_wmemmove.c b/library/wchar_wmemmove.c index 809ed84..06ffb54 100644 --- a/library/wchar_wmemmove.c +++ b/library/wchar_wmemmove.c @@ -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; } diff --git a/library/wchar_wmemset.c b/library/wchar_wmemset.c index a593d51..e584832 100644 --- a/library/wchar_wmemset.c +++ b/library/wchar_wmemset.c @@ -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; } diff --git a/library/wctype_iswalnum.c b/library/wctype_iswalnum.c index 14fd7b2..834ff00 100644 --- a/library/wctype_iswalnum.c +++ b/library/wctype_iswalnum.c @@ -37,9 +37,10 @@ /****************************************************************************/ +/* Implementation based on musl */ + int iswalnum(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return iswdigit(c) || iswalpha(c); } diff --git a/library/wctype_iswalpha.c b/library/wctype_iswalpha.c index 8840140..d90c00f 100644 --- a/library/wctype_iswalpha.c +++ b/library/wctype_iswalpha.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswalpha(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isalpha(c); } diff --git a/library/wctype_iswblank.c b/library/wctype_iswblank.c index a28f969..11fb9f3 100644 --- a/library/wctype_iswblank.c +++ b/library/wctype_iswblank.c @@ -35,11 +35,14 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ +/* Implementation based on musl */ + int iswblank(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isblank(c); } diff --git a/library/wctype_iswdigit.c b/library/wctype_iswdigit.c index dcb1595..46e5aeb 100644 --- a/library/wctype_iswdigit.c +++ b/library/wctype_iswdigit.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswdigit(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isdigit(c); } From ef18bf5f3e91d81a90b16d6eaa8b08a491b69f3b Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Wed, 28 Mar 2018 18:47:24 +0200 Subject: [PATCH 09/18] Fix vswprintf() prototype. --- library/include/wchar.h | 2 +- library/wchar_vswprintf.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/include/wchar.h b/library/include/wchar.h index e27b055..777ccba 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -168,7 +168,7 @@ extern int swprintf(wchar_t *s, const wchar_t *format, ...); extern int vfwprintf(FILE *stream,const wchar_t *format,va_list arg); extern int vwprintf(const wchar_t *format,va_list arg); -extern int vswprintf(char *s, const wchar_t *format,va_list arg); +extern int vswprintf(wchar_t *s, size_t maxlen, const wchar_t *format, va_list arg); /****************************************************************************/ diff --git a/library/wchar_vswprintf.c b/library/wchar_vswprintf.c index b2773f6..b296bdb 100644 --- a/library/wchar_vswprintf.c +++ b/library/wchar_vswprintf.c @@ -38,7 +38,7 @@ /****************************************************************************/ int -vswprintf(char *s, const wchar_t *format,va_list arg) +vswprintf(wchar_t *s, size_t maxlen, const wchar_t *format, va_list arg) { /* ZZZ unimplemented */ return(0); From 345995000ac81304caec03d220b049cdf4a4b8f9 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Wed, 28 Mar 2018 21:16:14 +0200 Subject: [PATCH 10/18] Implement some more of the iswXXX() functions. --- library/wctype_iswcntrl.c | 5 +++-- library/wctype_iswgraph.c | 5 +++-- library/wctype_iswlower.c | 5 +++-- library/wctype_iswpunc.c | 7 ++++--- library/wctype_iswspace.c | 5 +++-- library/wctype_iswupper.c | 5 +++-- library/wctype_iswxdigit.c | 5 +++-- 7 files changed, 22 insertions(+), 15 deletions(-) diff --git a/library/wctype_iswcntrl.c b/library/wctype_iswcntrl.c index 802422e..029e1d2 100644 --- a/library/wctype_iswcntrl.c +++ b/library/wctype_iswcntrl.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswcntrl(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return iscntrl(c); } diff --git a/library/wctype_iswgraph.c b/library/wctype_iswgraph.c index 3c63dba..5c18f87 100644 --- a/library/wctype_iswgraph.c +++ b/library/wctype_iswgraph.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswgraph(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isgraph(c); } diff --git a/library/wctype_iswlower.c b/library/wctype_iswlower.c index cac10a8..fe32f8d 100644 --- a/library/wctype_iswlower.c +++ b/library/wctype_iswlower.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswlower(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return islower(c); } diff --git a/library/wctype_iswpunc.c b/library/wctype_iswpunc.c index 40d98ea..62f4f09 100644 --- a/library/wctype_iswpunc.c +++ b/library/wctype_iswpunc.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int -iswpunc(wint_t c) +iswpunct(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return ispunct(c); } diff --git a/library/wctype_iswspace.c b/library/wctype_iswspace.c index 8c5afa4..ced9faf 100644 --- a/library/wctype_iswspace.c +++ b/library/wctype_iswspace.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswspace(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isspace(c); } diff --git a/library/wctype_iswupper.c b/library/wctype_iswupper.c index 5abc11e..e3f7bf9 100644 --- a/library/wctype_iswupper.c +++ b/library/wctype_iswupper.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswupper(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isupper(c); } diff --git a/library/wctype_iswxdigit.c b/library/wctype_iswxdigit.c index 3489cac..06e4b50 100644 --- a/library/wctype_iswxdigit.c +++ b/library/wctype_iswxdigit.c @@ -35,11 +35,12 @@ #include #endif /* _WCTYPE_HEADERS_H */ +#include + /****************************************************************************/ int iswxdigit(wint_t c) { - /* ZZZ unimplemented */ - return(0); + return isxdigit(c); } From 60eebbe7320681f8c715bec7c16a5e5bc9188fa2 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Wed, 28 Mar 2018 21:19:47 +0200 Subject: [PATCH 11/18] Implement wcscat(). --- library/wchar_wcscat.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/wchar_wcscat.c b/library/wchar_wcscat.c index 7859d14..dc605be 100644 --- a/library/wchar_wcscat.c +++ b/library/wchar_wcscat.c @@ -35,11 +35,13 @@ #include "wchar_headers.h" #endif /* _WCHAR_HEADERS_H */ +/* Implementation based on musl */ + /****************************************************************************/ wchar_t * wcscat(wchar_t *dest, const wchar_t *src) { - /* ZZZ unimplemented */ - return(NULL); + wcscpy(dest + wcslen(dest), src); + return dest; } From bc621bed9c654371a0e8c6e0065f4ea1d79a7c8b Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 29 Mar 2018 20:57:32 +0200 Subject: [PATCH 12/18] Disable the LOG_COMMAND. Piping will have the consequence that the exit status of the first command will not be considered. As this is the compiling command in our case, make will not exit with an error code even if the compiling failed. While there are shell-specific solutions, disabling LOG_COMMAND seems to be the most general solution. --- library/GNUmakefile.os4 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/library/GNUmakefile.os4 b/library/GNUmakefile.os4 index c232f5b..6fcd170 100644 --- a/library/GNUmakefile.os4 +++ b/library/GNUmakefile.os4 @@ -29,7 +29,11 @@ RANLIB := ppc-amigaos-ranlib COPY := cp -p DELETE := rm -rf MAKEDIR := mkdir -p -LOG_COMMAND := 2>&1 | tee -a compiler.log +# Enabling the LOG_COMMAND has the consequence that a rule will not +# fail on an error because only the exit status from the tee command +# will be considered +#LOG_COMMAND := 2>&1 | tee -a compiler.log +LOG_COMMAND := # You may need to request a specific compiler version in order to # build the baserel versions of the library. At this time of # writing (2008-11-06) GCC 4.0.4 and below support the -mbaserel From d1092099d0a584ebd56027a043104d02e3d331ad Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 29 Mar 2018 20:59:02 +0200 Subject: [PATCH 13/18] Provide some more wide char functions. --- library/include/wchar.h | 2 +- library/libc.gmk | 1 + library/wchar_mbsinit.c | 3 +-- library/wchar_wcschr.c | 7 ++++-- library/wchar_wcscspn.c | 50 +++++++++++++++++++++++++++++++++++++++++ library/wchar_wcsncmp.c | 6 +++-- library/wchar_wcsncpy.c | 8 +++++-- 7 files changed, 68 insertions(+), 9 deletions(-) create mode 100644 library/wchar_wcscspn.c diff --git a/library/include/wchar.h b/library/include/wchar.h index 777ccba..a9047d6 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -192,7 +192,7 @@ extern size_t mbsrtowcs(wchar_t *restrict dst, const char **restrict src, size_t extern size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict ps); extern int wcscoll(const wchar_t *ws1, const wchar_t *ws2); extern int wcscoll_l(const wchar_t *ws1, const wchar_t *ws2, locale_t loc); -extern size_t wcscspn(const wchar_t *ws1, const wchar_t *ws2); +extern size_t wcscspn(const wchar_t *s, const wchar_t *c); extern size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict src, size_t nwc, size_t len, mbstate_t *restrict ps); extern wchar_t * wcsrchr(const wchar_t *ws, wchar_t wc); extern size_t wcsrtombs(char *restrict dst, const wchar_t **restrict src, size_t len, mbstate_t *restrict ps); diff --git a/library/libc.gmk b/library/libc.gmk index 63707e5..cd92dc9 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -402,6 +402,7 @@ C_LIB := \ wchar_wcschr.o \ wchar_wcscmp.o \ wchar_wcscpy.o \ + wchar_wcscspn.o \ wchar_wcsftime.o \ wchar_wcslen.o \ wchar_wcsncat.o \ diff --git a/library/wchar_mbsinit.c b/library/wchar_mbsinit.c index 1233ae1..44dc9b5 100644 --- a/library/wchar_mbsinit.c +++ b/library/wchar_mbsinit.c @@ -40,6 +40,5 @@ int mbsinit(const mbstate_t *ps) { - /* ZZZ unimplemented */ - return(0); + return !ps || !*(unsigned *)ps; } diff --git a/library/wchar_wcschr.c b/library/wchar_wcschr.c index c2d4fbd..12c44b9 100644 --- a/library/wchar_wcschr.c +++ b/library/wchar_wcschr.c @@ -37,9 +37,12 @@ /****************************************************************************/ +/* Implementation based on musl */ + wchar_t * wcschr(const wchar_t *s, wchar_t c) { - /* ZZZ unimplemented */ - return(NULL); + if (!c) return (wchar_t *)s + wcslen(s); + for (; *s && *s != c; s++); + return *s ? (wchar_t *)s : 0; } diff --git a/library/wchar_wcscspn.c b/library/wchar_wcscspn.c new file mode 100644 index 0000000..a43782f --- /dev/null +++ b/library/wchar_wcscspn.c @@ -0,0 +1,50 @@ +/* + * $Id: wchar_wcsspn.c,v 1.3 2006-01-08 12:04:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2015 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +/* Implementation based on musl */ + +size_t +wcscspn(const wchar_t *s, const wchar_t *c) +{ + const wchar_t *a; + if (!c[0]) return wcslen(s); + if (!c[1]) return (s=wcschr(a=s, *c)) ? (size_t)(s-a) : wcslen(a); + for (a=s; *s && !wcschr(c, *s); s++); + return s-a; +} diff --git a/library/wchar_wcsncmp.c b/library/wchar_wcsncmp.c index dc62d39..4363d3f 100644 --- a/library/wchar_wcsncmp.c +++ b/library/wchar_wcsncmp.c @@ -37,9 +37,11 @@ /****************************************************************************/ +/* Implementation based on musl */ + int wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) { - /* ZZZ unimplemented */ - return(0); + for (; n && *s1==*s2 && *s1 && *s2; n--, s1++, s2++); + return n ? *s1 - *s2 : 0; } diff --git a/library/wchar_wcsncpy.c b/library/wchar_wcsncpy.c index 0862776..f969bfd 100644 --- a/library/wchar_wcsncpy.c +++ b/library/wchar_wcsncpy.c @@ -37,9 +37,13 @@ /****************************************************************************/ +/* Implementation based on musl */ + wchar_t * wcsncpy(wchar_t *dest, const wchar_t *src, size_t n) { - /* ZZZ unimplemented */ - return(NULL); + wchar_t *a = dest; + while (n && *src) n--, *dest++ = *src++; + wmemset(dest, 0, n); + return a; } From eb1d784c0de76c1e8ef66ba141d005dfa12276b1 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Fri, 30 Mar 2018 21:21:11 +0200 Subject: [PATCH 14/18] Provide stub for mbrtowc(). --- library/libc.gmk | 1 + library/wchar_mbrtowc.c | 64 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 library/wchar_mbrtowc.c diff --git a/library/libc.gmk b/library/libc.gmk index cd92dc9..58e0a17 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -387,6 +387,7 @@ C_LIB := \ wchar_getwc.o \ wchar_getwchar.o \ wchar_mbrlen.o \ + wchar_mbrtowc.o \ wchar_mbsinit.o \ wchar_mbsrtowcs.o \ wchar_putwc.o \ diff --git a/library/wchar_mbrtowc.c b/library/wchar_mbrtowc.c new file mode 100644 index 0000000..05f59c0 --- /dev/null +++ b/library/wchar_mbrtowc.c @@ -0,0 +1,64 @@ +/* + * $Id: wchar_mbrlen.c,v 1.3 2006-01-08 12:04:27 obarthel Exp $ + * + * :ts=4 + * + * Portable ISO 'C' (1994) runtime library for the Amiga computer + * Copyright (c) 2002-2015 by Olaf Barthel + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Neither the name of Olaf Barthel nor the names of contributors + * may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _WCHAR_HEADERS_H +#include "wchar_headers.h" +#endif /* _WCHAR_HEADERS_H */ + +/****************************************************************************/ + +/* Mostly non-working stub based on bionic */ + +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) +size_t +mbrtowc(wchar_t *restrict pwc, const char *restrict s, size_t n, mbstate_t *restrict ps) +{ + if (s == NULL) + { + s = ""; + pwc = NULL; + } + + if (n == 0) + { + if (pwc) + *pwc = 0; + return 0; + } + + if (pwc) + *pwc = *s; + + return (*s != 0); +} +#endif /* __STDC_VERSION__ && __STDC_VERSION__ >= 199901L */ From a6a9352a0044194a7496e44e0407dee8c0496dc5 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Fri, 30 Mar 2018 21:21:31 +0200 Subject: [PATCH 15/18] Compile wchar_wscoll.c. --- library/libc.gmk | 1 + 1 file changed, 1 insertion(+) diff --git a/library/libc.gmk b/library/libc.gmk index 58e0a17..e0ea214 100644 --- a/library/libc.gmk +++ b/library/libc.gmk @@ -409,6 +409,7 @@ C_LIB := \ wchar_wcsncat.o \ wchar_wcsncmp.o \ wchar_wcsncpy.o \ + wchar_wscoll.o \ wchar_wcspbrk.o \ wchar_wcsrtombs.o \ wchar_wcsspn.o \ From dfc7f310d6f72cf9b70fa30d1649bc4bff4d47b4 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Fri, 30 Mar 2018 21:35:06 +0200 Subject: [PATCH 16/18] Don't define wchar_t in C++ as it is a bultin-type there. --- library/include/stddef.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/library/include/stddef.h b/library/include/stddef.h index 817af4d..b78b0eb 100644 --- a/library/include/stddef.h +++ b/library/include/stddef.h @@ -61,7 +61,11 @@ extern "C" { typedef int ptrdiff_t; typedef unsigned int size_t; + +/* wchar_t is a built-in type in C++ */ +#ifndef __cplusplus typedef unsigned short wchar_t; +#endif /****************************************************************************/ From 3e50be491ba4a0c6fe7f21c29d5376dfcd5f295a Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Fri, 30 Mar 2018 21:42:12 +0200 Subject: [PATCH 17/18] Include stdint.h for WCHAR_MAX to avoid redundant definitions. --- library/include/wchar.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/include/wchar.h b/library/include/wchar.h index a9047d6..053a80d 100644 --- a/library/include/wchar.h +++ b/library/include/wchar.h @@ -67,6 +67,10 @@ #include #endif /* _LOCALE_H */ +#ifndef _STDINT_H +#include +#endif + /****************************************************************************/ #ifdef __cplusplus @@ -76,8 +80,6 @@ extern "C" { /****************************************************************************/ #define WEOF (-1) -#define WCHAR_MAX 65535 -#define WCHAR_MIN 0 /****************************************************************************/ From febe89c61b34809f8c4a35ed8f231be621b00d0e Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Fri, 30 Mar 2018 22:17:41 +0200 Subject: [PATCH 18/18] Update changelog. --- library/changes | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/library/changes b/library/changes index a76cfee..f6b57d8 100644 --- a/library/changes +++ b/library/changes @@ -1,3 +1,11 @@ +c.lib 1.216 (xxx) + +- Add some wchar and multbyte-string related functions to allow gcc + building a libstdc++ library with wide char support. For now, the + functions are mostly stub ones only. They can be implemented on + demand. + + c.lib 1.215 (26.6.2017) - Added -fno-aggressive-loop-optimizations option when building crtbegin.c