diff --git a/src/system/libroot/posix/glibc/stdlib/Jamfile b/src/system/libroot/posix/glibc/stdlib/Jamfile index 92bb5a2d02..21122d50c6 100644 --- a/src/system/libroot/posix/glibc/stdlib/Jamfile +++ b/src/system/libroot/posix/glibc/stdlib/Jamfile @@ -20,9 +20,9 @@ MergeObject posix_gnu_stdlib.o : lcong48_r.c lrand48.c lrand48_r.c - mblen.c - mbstowcs.c - mbtowc.c + #mblen.c + #mbstowcs.c + #mbtowc.c mrand48.c mrand48_r.c nrand48.c @@ -32,6 +32,6 @@ MergeObject posix_gnu_stdlib.o : seed48_r.c srand48.c srand48_r.c - wcstombs.c - wctomb.c + #wcstombs.c + #wctomb.c ; diff --git a/src/system/libroot/posix/glibc/wcsmbs/Jamfile b/src/system/libroot/posix/glibc/wcsmbs/Jamfile index a72907ab0f..1ea2051687 100644 --- a/src/system/libroot/posix/glibc/wcsmbs/Jamfile +++ b/src/system/libroot/posix/glibc/wcsmbs/Jamfile @@ -19,14 +19,14 @@ SubDirCcFlags -D_GNU_SOURCE -DUSE_IN_LIBIO ; MergeObject posix_gnu_wcsmbs.o : btowc.c mbrlen.c - mbrtowc.c - mbsinit.c - mbsnrtowcs.c +# mbrtowc.c +# mbsinit.c +# mbsnrtowcs.c mbsrtowcs.c # mbsrtowcs_l.c wcpcpy.c wcpncpy.c - wcrtomb.c +# wcrtomb.c wcscasecmp.c # wcscasecmp_l.c wcscat.c diff --git a/src/system/libroot/posix/locale/Jamfile b/src/system/libroot/posix/locale/Jamfile index ac1179ea0d..7324512b86 100644 --- a/src/system/libroot/posix/locale/Jamfile +++ b/src/system/libroot/posix/locale/Jamfile @@ -4,4 +4,9 @@ MergeObject posix_locale.o : #ctype.c localeconv.c setlocale.c + mb_none.c + mblen.c + mbrtowc.c + mbsinit.c + wcrtomb.c ; diff --git a/src/system/libroot/posix/locale/mb_defs.h b/src/system/libroot/posix/locale/mb_defs.h new file mode 100755 index 0000000000..be183f2b59 --- /dev/null +++ b/src/system/libroot/posix/locale/mb_defs.h @@ -0,0 +1,49 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + * + * $FreeBSD: src/lib/libc/locale/mblocal.h,v 1.5.18.1 2008/11/25 02:59:29 kensmith Exp $ + */ + +#ifndef _MB_DEFS_H_ +#define _MB_DEFS_H_ + +/* + * Conversion function pointers for current encoding. + */ +extern size_t (*__mbrtowc)(wchar_t *, const char *, + size_t, mbstate_t *); +extern int (*__mbsinit)(const mbstate_t *); +extern size_t (*__mbsnrtowcs)(wchar_t *, const char **, + size_t, size_t, mbstate_t *); +extern size_t (*__wcrtomb)(char *, wchar_t, mbstate_t *); +extern size_t (*__wcsnrtombs)(char *, const wchar_t **, + size_t, size_t, mbstate_t *); + +extern size_t __mbsnrtowcs_std(wchar_t * , const char **, + size_t, size_t, mbstate_t * ); +extern size_t __wcsnrtombs_std(char * , const wchar_t **, + size_t, size_t, mbstate_t * ); + +#endif /* _MB_DEFS_H_ */ diff --git a/src/system/libroot/posix/locale/mb_none.c b/src/system/libroot/posix/locale/mb_none.c new file mode 100755 index 0000000000..c74e1ad26a --- /dev/null +++ b/src/system/libroot/posix/locale/mb_none.c @@ -0,0 +1,205 @@ +/* +** Copyright 2009, Stefano Ceccherini, stefano.ceccherini@gmail.com. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. All rights reserved. + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)none.c 8.1 (Berkeley) 6/4/93"; +#endif /* LIBC_SCCS and not lint */ +#include + +/*__FBSDID("$FreeBSD: src/lib/libc/locale/none.c,v 1.14.2.1.4.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include +#include +#include +#include +#include +#include + +#include "mb_defs.h" + +static size_t _none_mbrtowc(wchar_t * , const char * , + size_t, mbstate_t * ); +static int _none_mbsinit(const mbstate_t *); +static size_t _none_mbsnrtowcs(wchar_t * dst, + const char ** src, size_t nms, size_t len, + mbstate_t * ps); +static size_t _none_wcrtomb(char * , wchar_t, + mbstate_t * ); +static size_t _none_wcsnrtombs(char * , const wchar_t ** , + size_t, size_t, mbstate_t * ); + +/* setup defaults */ + +int __mb_cur_max = 1; +int __mb_sb_limit = 256; + +int +_none_init() +{ + + __mbrtowc = _none_mbrtowc; + __mbsinit = _none_mbsinit; + __mbsnrtowcs = _none_mbsnrtowcs; + __wcrtomb = _none_wcrtomb; + __wcsnrtombs = _none_wcsnrtombs; + __mb_cur_max = 1; + __mb_sb_limit = 256; + return(0); +} + + +static int +_none_mbsinit(const mbstate_t *ps) +{ + + /* + * Encoding is not state dependent - we are always in the + * initial state. + */ + return (1); +} + + +static size_t +_none_mbrtowc(wchar_t * pwc, const char * s, size_t n, + mbstate_t * ps) +{ + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (0); + if (n == 0) + /* Incomplete multibyte sequence */ + return ((size_t)-2); + if (pwc != NULL) + *pwc = (unsigned char)*s; + return (*s == '\0' ? 0 : 1); +} + + +static size_t +_none_wcrtomb(char * s, wchar_t wc, + mbstate_t * ps) +{ + + if (s == NULL) + /* Reset to initial shift state (no-op) */ + return (1); + if (wc < 0 || wc > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + *s = (unsigned char)wc; + return (1); +} + + +static size_t +_none_mbsnrtowcs(wchar_t * dst, const char ** src, + size_t nms, size_t len, mbstate_t * ps) +{ + const char *s; + size_t nchr; + + if (dst == NULL) { + s = memchr(*src, '\0', nms); + return (s != NULL ? s - *src : nms); + } + + s = *src; + nchr = 0; + while (len-- > 0 && nms-- > 0) { + if ((*dst++ = (unsigned char)*s++) == L'\0') { + *src = NULL; + return (nchr); + } + nchr++; + } + *src = s; + return (nchr); +} + + +static size_t +_none_wcsnrtombs(char * dst, const wchar_t ** src, + size_t nwc, size_t len, mbstate_t * ps) +{ + const wchar_t *s; + size_t nchr; + + if (dst == NULL) { + for (s = *src; nwc > 0 && *s != L'\0'; s++, nwc--) { + if (*s < 0 || *s > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + } + return (s - *src); + } + + s = *src; + nchr = 0; + while (len-- > 0 && nwc-- > 0) { + if (*s < 0 || *s > UCHAR_MAX) { + errno = EILSEQ; + return ((size_t)-1); + } + if ((*dst++ = *s++) == '\0') { + *src = NULL; + return (nchr); + } + nchr++; + } + *src = s; + return (nchr); +} + + +/* setup defaults */ + +size_t (*__mbrtowc)(wchar_t * , const char * , size_t, + mbstate_t * ) = _none_mbrtowc; +int (*__mbsinit)(const mbstate_t *) = _none_mbsinit; +size_t (*__mbsnrtowcs)(wchar_t * , const char ** , + size_t, size_t, mbstate_t * ) = _none_mbsnrtowcs; +size_t (*__wcrtomb)(char * , wchar_t, mbstate_t * ) = + _none_wcrtomb; +size_t (*__wcsnrtombs)(char * , const wchar_t ** , + size_t, size_t, mbstate_t * ) = _none_wcsnrtombs; + diff --git a/src/system/libroot/posix/locale/mblen.c b/src/system/libroot/posix/locale/mblen.c new file mode 100755 index 0000000000..044c95b2d2 --- /dev/null +++ b/src/system/libroot/posix/locale/mblen.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +/*__FBSDID("$FreeBSD: src/lib/libc/locale/mblen.c,v 1.9.26.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include +#include "mb_defs.h" + +int +mblen(const char *s, size_t n) +{ + static const mbstate_t initial; + static mbstate_t mbs; + size_t rval; + + if (s == NULL) { + /* No support for state dependent encodings. */ + mbs = initial; + return (0); + } + rval = __mbrtowc(NULL, s, n, &mbs); + if (rval == (size_t)-1 || rval == (size_t)-2) + return (-1); + return ((int)rval); +} diff --git a/src/system/libroot/posix/locale/mbrlen.c b/src/system/libroot/posix/locale/mbrlen.c new file mode 100755 index 0000000000..9a0fff4222 --- /dev/null +++ b/src/system/libroot/posix/locale/mbrlen.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +/*__FBSDID("$FreeBSD: src/lib/libc/locale/mbrlen.c,v 1.4.26.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include "mb_defs.h" + +size_t +mbrlen(const char *s, size_t n, mbstate_t *ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__mbrtowc(NULL, s, n, ps)); +} diff --git a/src/system/libroot/posix/locale/mbrtowc.c b/src/system/libroot/posix/locale/mbrtowc.c new file mode 100755 index 0000000000..c3b569c3eb --- /dev/null +++ b/src/system/libroot/posix/locale/mbrtowc.c @@ -0,0 +1,42 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +/*__FBSDID("$FreeBSD: src/lib/libc/locale/mbrtowc.c,v 1.7.26.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include "mb_defs.h" + +size_t +mbrtowc(wchar_t *pwc, const char *s, + size_t n, mbstate_t *ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__mbrtowc(pwc, s, n, ps)); +} diff --git a/src/system/libroot/posix/locale/mbsinit.c b/src/system/libroot/posix/locale/mbsinit.c new file mode 100755 index 0000000000..4a50583d56 --- /dev/null +++ b/src/system/libroot/posix/locale/mbsinit.c @@ -0,0 +1,38 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +/*__FBSDID("$FreeBSD: src/lib/libc/locale/mbsinit.c,v 1.3.26.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include "mb_defs.h" + +int +mbsinit(const mbstate_t *ps) +{ + + return (__mbsinit(ps)); +} diff --git a/src/system/libroot/posix/locale/wcrtomb.c b/src/system/libroot/posix/locale/wcrtomb.c new file mode 100755 index 0000000000..d1318d4c29 --- /dev/null +++ b/src/system/libroot/posix/locale/wcrtomb.c @@ -0,0 +1,41 @@ +/*- + * Copyright (c) 2002-2004 Tim J. Robbins. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. + */ + +#include +/*__FBSDID("$FreeBSD: src/lib/libc/locale/wcrtomb.c,v 1.8.26.1 2008/11/25 02:59:29 kensmith Exp $"); */ + +#include +#include "mb_defs.h" + +size_t +wcrtomb(char *s, wchar_t wc, mbstate_t *ps) +{ + static mbstate_t mbs; + + if (ps == NULL) + ps = &mbs; + return (__wcrtomb(s, wc, ps)); +}