Merge pull request #7 from sba1/wchar-fixes

Wchar fixes
This commit is contained in:
Sebastian Bauer 2018-03-31 09:37:50 +02:00 committed by GitHub
commit 425f899302
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 365 additions and 63 deletions

View File

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

View File

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

View File

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

View File

@ -43,6 +43,10 @@
/****************************************************************************/
#ifndef _SYS_CLIB2_STDC_H
#include <sys/clib2_stdc.h>
#endif /* _SYS_CLIB2_STDC_H */
#ifndef _STDDEF_H
#include <stddef.h>
#endif /* _STDDEF_H */
@ -63,6 +67,10 @@
#include <locale.h>
#endif /* _LOCALE_H */
#ifndef _STDINT_H
#include <stdint.h>
#endif
/****************************************************************************/
#ifdef __cplusplus
@ -72,8 +80,6 @@ extern "C" {
/****************************************************************************/
#define WEOF (-1)
#define WCHAR_MAX 65535
#define WCHAR_MIN 0
/****************************************************************************/
@ -164,7 +170,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);
/****************************************************************************/
@ -177,7 +183,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);
@ -186,8 +192,9 @@ 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 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);

View File

@ -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 \
@ -374,7 +375,78 @@ 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_mbrtowc.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_wcscspn.o \
wchar_wcsftime.o \
wchar_wcslen.o \
wchar_wcsncat.o \
wchar_wcsncmp.o \
wchar_wcsncpy.o \
wchar_wscoll.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
##############################################################################

View File

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

64
library/wchar_mbrtowc.c Normal file
View File

@ -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 <obarthel (at) gmx.net>
* 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 */

View File

@ -40,6 +40,5 @@
int
mbsinit(const mbstate_t *ps)
{
/* ZZZ unimplemented */
return(0);
return !ps || !*(unsigned *)ps;
}

View File

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

View File

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

View File

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

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;
}

50
library/wchar_wcscspn.c Normal file
View File

@ -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 <obarthel (at) gmx.net>
* 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;
}

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

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

View File

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

View File

@ -37,7 +37,7 @@
/****************************************************************************/
wchar_t
wchar_t *
wcspbrk(const wchar_t *s, const wchar_t *set)
{
/* ZZZ unimplemented */

45
library/wchar_wctob.c Normal file
View File

@ -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 <obarthel (at) gmx.net>
* 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)
{
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
iswcntrl(wint_t c)
{
/* ZZZ unimplemented */
return(0);
return iscntrl(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);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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