From e85f78a20b762edb673a2854f5720e8269bc817a Mon Sep 17 00:00:00 2001 From: Kees van Reeuwijk Date: Mon, 19 Apr 2010 15:20:24 +0000 Subject: [PATCH] Add some support for wchar_t. --- include/Makefile | 2 +- lib/libc/Makefile | 1 + lib/libc/wchar/Makefile.inc | 33 ++++++++++++ lib/libc/wchar/towlower.c | 15 ++++++ lib/libc/wchar/towupper.c | 15 ++++++ lib/libc/wchar/wcscasecmp.c | 37 +++++++++++++ lib/libc/wchar/wcscat.c | 51 ++++++++++++++++++ lib/libc/wchar/wcschr.c | 46 +++++++++++++++++ lib/libc/wchar/wcscmp.c | 51 ++++++++++++++++++ lib/libc/wchar/wcscpy.c | 43 ++++++++++++++++ lib/libc/wchar/wcscspn.c | 54 +++++++++++++++++++ lib/libc/wchar/wcsdup.c | 31 +++++++++++ lib/libc/wchar/wcslcat.c | 68 ++++++++++++++++++++++++ lib/libc/wchar/wcslcpy.c | 64 +++++++++++++++++++++++ lib/libc/wchar/wcslen.c | 45 ++++++++++++++++ lib/libc/wchar/wcsncasecmp.c | 42 +++++++++++++++ lib/libc/wchar/wcsncat.c | 53 +++++++++++++++++++ lib/libc/wchar/wcsncmp.c | 51 ++++++++++++++++++ lib/libc/wchar/wcsncpy.c | 50 ++++++++++++++++++ lib/libc/wchar/wcspbrk.c | 52 +++++++++++++++++++ lib/libc/wchar/wcsrchr.c | 48 +++++++++++++++++ lib/libc/wchar/wcsspn.c | 56 ++++++++++++++++++++ lib/libc/wchar/wcsstr.c | 67 ++++++++++++++++++++++++ lib/libc/wchar/wcstok.c | 94 ++++++++++++++++++++++++++++++++++ lib/libc/wchar/wcstombs.c | 20 ++++++++ lib/libc/wchar/wcswcs.c | 2 + lib/libc/wchar/wctomb.c | 19 +++++++ lib/libc/wchar/wmemchr.c | 45 ++++++++++++++++ lib/libc/wchar/wmemcmp.c | 49 ++++++++++++++++++ lib/libc/wchar/wmemcpy.c | 40 +++++++++++++++ lib/libc/wchar/wmemmove.c | 40 +++++++++++++++ lib/libc/wchar/wmemset.c | 46 +++++++++++++++++ servers/inet/generic/ip_read.c | 12 ++--- 33 files changed, 1333 insertions(+), 9 deletions(-) create mode 100644 lib/libc/wchar/Makefile.inc create mode 100644 lib/libc/wchar/towlower.c create mode 100644 lib/libc/wchar/towupper.c create mode 100644 lib/libc/wchar/wcscasecmp.c create mode 100644 lib/libc/wchar/wcscat.c create mode 100644 lib/libc/wchar/wcschr.c create mode 100644 lib/libc/wchar/wcscmp.c create mode 100644 lib/libc/wchar/wcscpy.c create mode 100644 lib/libc/wchar/wcscspn.c create mode 100644 lib/libc/wchar/wcsdup.c create mode 100644 lib/libc/wchar/wcslcat.c create mode 100644 lib/libc/wchar/wcslcpy.c create mode 100644 lib/libc/wchar/wcslen.c create mode 100644 lib/libc/wchar/wcsncasecmp.c create mode 100644 lib/libc/wchar/wcsncat.c create mode 100644 lib/libc/wchar/wcsncmp.c create mode 100644 lib/libc/wchar/wcsncpy.c create mode 100644 lib/libc/wchar/wcspbrk.c create mode 100644 lib/libc/wchar/wcsrchr.c create mode 100644 lib/libc/wchar/wcsspn.c create mode 100644 lib/libc/wchar/wcsstr.c create mode 100644 lib/libc/wchar/wcstok.c create mode 100644 lib/libc/wchar/wcstombs.c create mode 100644 lib/libc/wchar/wcswcs.c create mode 100644 lib/libc/wchar/wctomb.c create mode 100644 lib/libc/wchar/wmemchr.c create mode 100644 lib/libc/wchar/wmemcmp.c create mode 100644 lib/libc/wchar/wmemcpy.c create mode 100644 lib/libc/wchar/wmemmove.c create mode 100644 lib/libc/wchar/wmemset.c diff --git a/include/Makefile b/include/Makefile index c1cfd8fcb..3ba9e2b76 100644 --- a/include/Makefile +++ b/include/Makefile @@ -8,7 +8,7 @@ INCS= alloca.h ansi.h a.out.h ar.h assert.h configfile.h ctype.h \ regexp.h setjmp.h sgtty.h signal.h stdarg.h stddef.h \ stdint.h stdio.h stdlib.h string.h strings.h sysexits.h \ syslog.h tar.h termcap.h termios.h time.h timers.h tools.h \ - ttyent.h ucontext.h unistd.h utime.h utmp.h + ttyent.h ucontext.h unistd.h utime.h utmp.h wchar.h wctype.h INCS+= arpa/inet.h INCS+= minix/a.out.h minix/bitmap.h minix/callnr.h minix/cdrom.h \ minix/com.h minix/config.h minix/const.h minix/cpufeature.h \ diff --git a/lib/libc/Makefile b/lib/libc/Makefile index e24a63d6f..7e95cb1c4 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -7,6 +7,7 @@ LIB= c CPPFLAGS+=-O -D_MINIX -D_POSIX_SOURCE .include "${.CURDIR}/ansi/Makefile.inc" +.include "${.CURDIR}/wchar/Makefile.inc" .include "${.CURDIR}/ip/Makefile.inc" .include "${.CURDIR}/math/Makefile.inc" .include "${.CURDIR}/other/Makefile.inc" diff --git a/lib/libc/wchar/Makefile.inc b/lib/libc/wchar/Makefile.inc new file mode 100644 index 000000000..a0355af95 --- /dev/null +++ b/lib/libc/wchar/Makefile.inc @@ -0,0 +1,33 @@ +# wchar sources +.PATH: ${.CURDIR}/wchar + +SRCS+= \ + towupper.c \ + towlower.c \ + wcscasecmp.c \ + wcscat.c \ + wcschr.c \ + wcscmp.c \ + wcscpy.c \ + wcscspn.c \ + wcsdup.c \ + wcslcat.c \ + wcslcpy.c \ + wcslen.c \ + wcsncasecmp.c \ + wcsncat.c \ + wcsncmp.c \ + wcsncpy.c \ + wcspbrk.c \ + wcsrchr.c \ + wcsspn.c \ + wcsstr.c \ + wcstok.c \ + wcstombs.c \ + wcswcs.c \ + wctomb.c \ + wmemchr.c \ + wmemcmp.c \ + wmemcpy.c \ + wmemmove.c \ + wmemset.c diff --git a/lib/libc/wchar/towlower.c b/lib/libc/wchar/towlower.c new file mode 100644 index 000000000..897e686b3 --- /dev/null +++ b/lib/libc/wchar/towlower.c @@ -0,0 +1,15 @@ +/* + * Very lame implementation of towlower that simply applies tolower + * if the character is within range of 'normal' characters. + */ + +#include +#include + +wint_t towlower(wint_t c) +{ + if( c>0xff ){ + return c; + } + return (wint_t) tolower((char) c); +} diff --git a/lib/libc/wchar/towupper.c b/lib/libc/wchar/towupper.c new file mode 100644 index 000000000..920e1124e --- /dev/null +++ b/lib/libc/wchar/towupper.c @@ -0,0 +1,15 @@ +/* + * Very lame implementation of towupper that simply applies toupper + * if the character is within range of 'normal' characters. + */ + +#include +#include + +wint_t towupper(wint_t c) +{ + if( c>0xff ){ + return c; + } + return (wint_t) toupper((char) c); +} diff --git a/lib/libc/wchar/wcscasecmp.c b/lib/libc/wchar/wcscasecmp.c new file mode 100644 index 000000000..046715773 --- /dev/null +++ b/lib/libc/wchar/wcscasecmp.c @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006 Aleksey Cheusov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee. Permission to modify the code and to distribute modified + * code is also granted without any restrictions. + */ + +#include +#include +#include + +int +wcscasecmp(const wchar_t *s1, const wchar_t *s2) +{ + + assert(s1 != NULL); + assert(s2 != NULL); + + for (;;) { + int lc1 = towlower(*s1); + int lc2 = towlower(*s2); + + int diff = lc1 - lc2; + if (diff != 0) + return diff; + + if (!lc1) + return 0; + + ++s1; + ++s2; + } +} diff --git a/lib/libc/wchar/wcscat.c b/lib/libc/wchar/wcscat.c new file mode 100644 index 000000000..0c7fd4fff --- /dev/null +++ b/lib/libc/wchar/wcscat.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcscat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#include + +wchar_t * +wcscat(wchar_t *s1, const wchar_t *s2) +{ + wchar_t *p; + wchar_t *q; + const wchar_t *r; + + assert(s1 != NULL); + assert(s2 != NULL); + + p = s1; + while (*p) + p++; + q = p; + r = s2; + while (*r) + *q++ = *r++; + *q = '\0'; + return s1; +} diff --git a/lib/libc/wchar/wcschr.c b/lib/libc/wchar/wcschr.c new file mode 100644 index 000000000..2285e3641 --- /dev/null +++ b/lib/libc/wchar/wcschr.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcschr.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include +#include + +wchar_t * +wcschr(const wchar_t *p, wchar_t c) +{ + assert(p != NULL); + + for (;; ++p) { + if (*p == c) { + /* LINTED interface specification */ + return (wchar_t *) p; + } + if (!*p) + return NULL; + } + /*NOTREACHED*/ +} diff --git a/lib/libc/wchar/wcscmp.c b/lib/libc/wchar/wcscmp.c new file mode 100644 index 000000000..d07fd52de --- /dev/null +++ b/lib/libc/wchar/wcscmp.c @@ -0,0 +1,51 @@ +/*- + * Copyright (c) 1990, 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Chris Torek. + * + * 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. + * 3. 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. + */ + +#include +#include + +/* + * Compare strings. + */ +int +wcscmp(const wchar_t *s1, const wchar_t *s2) +{ + + assert(s1 != NULL); + assert(s2 != NULL); + + while (*s1 == *s2++) + if (*s1++ == 0) + return (0); + /* XXX assumes wchar_t = int */ + return (*s1 - *--s2); +} diff --git a/lib/libc/wchar/wcscpy.c b/lib/libc/wchar/wcscpy.c new file mode 100644 index 000000000..9f969b441 --- /dev/null +++ b/lib/libc/wchar/wcscpy.c @@ -0,0 +1,43 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcscpy.c,v 1.2 2000/12/21 04:51:09 itojun Exp + */ + +#include +#include + +wchar_t * +wcscpy(wchar_t *s1, const wchar_t *s2) +{ + wchar_t *p; + + assert(s1 != NULL); + assert(s2 != NULL); + + for (p = s1; (*p = *s2) != L'\0'; ++p, ++s2); + + return s1; +} diff --git a/lib/libc/wchar/wcscspn.c b/lib/libc/wchar/wcscspn.c new file mode 100644 index 000000000..24fdc2099 --- /dev/null +++ b/lib/libc/wchar/wcscspn.c @@ -0,0 +1,54 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcscspn.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#include + +size_t +wcscspn(const wchar_t *s, const wchar_t *set) +{ + const wchar_t *p; + const wchar_t *q; + + assert(s != NULL); + assert(set != NULL); + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) + goto done; + q++; + } + p++; + } + +done: + return (p - s); +} diff --git a/lib/libc/wchar/wcsdup.c b/lib/libc/wchar/wcsdup.c new file mode 100644 index 000000000..fe42ce802 --- /dev/null +++ b/lib/libc/wchar/wcsdup.c @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2006 Aleksey Cheusov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee. Permission to modify the code and to distribute modified + * code is also granted without any restrictions. + */ + +#include +#include +#include + +wchar_t * +wcsdup(const wchar_t *str) +{ + wchar_t *copy; + size_t len; + + assert(str != NULL); + + len = wcslen(str) + 1; + copy = malloc(len * sizeof (wchar_t)); + + if (!copy) + return NULL; + + return wmemcpy(copy, str, len); +} diff --git a/lib/libc/wchar/wcslcat.c b/lib/libc/wchar/wcslcat.c new file mode 100644 index 000000000..d213a3e48 --- /dev/null +++ b/lib/libc/wchar/wcslcat.c @@ -0,0 +1,68 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 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 +#include +#include + +/* + * Appends src to string dst of size siz (unlike wcsncat, siz is the + * full size of dst, not space left). At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns wcslen(initial dst) + wcslen(src); if retval >= siz, + * truncation occurred. + */ +size_t +wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) +{ + wchar_t *d = dst; + const wchar_t *s = src; + size_t n = siz; + size_t dlen; + + assert(dst != NULL); + assert(src != NULL); + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; + + if (n == 0) + return(dlen + wcslen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return(dlen + (s - src)); /* count does not include NUL */ +} diff --git a/lib/libc/wchar/wcslcpy.c b/lib/libc/wchar/wcslcpy.c new file mode 100644 index 000000000..bd99485ce --- /dev/null +++ b/lib/libc/wchar/wcslcpy.c @@ -0,0 +1,64 @@ +/* + * Copyright (c) 1998 Todd C. Miller + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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 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 +#include +#include + +/* + * Copy src to string dst of size siz. At most siz-1 characters + * will be copied. Always NUL terminates (unless siz == 0). + * Returns wcslen(src); if retval >= siz, truncation occurred. + */ +size_t +wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz) +{ + wchar_t *d = dst; + const wchar_t *s = src; + size_t n = siz; + + assert(dst != NULL); + assert(src != NULL); + + /* Copy as many bytes as will fit */ + if (n != 0 && --n != 0) { + do { + if ((*d++ = *s++) == 0) + break; + } while (--n != 0); + } + + /* Not enough room in dst, add NUL and traverse rest of src */ + if (n == 0) { + if (siz != 0) + *d = '\0'; /* NUL-terminate dst */ + while (*s++) + ; + } + + return(s - src - 1); /* count does not include NUL */ +} diff --git a/lib/libc/wchar/wcslen.c b/lib/libc/wchar/wcslen.c new file mode 100644 index 000000000..0442e905e --- /dev/null +++ b/lib/libc/wchar/wcslen.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcslen.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#include + +size_t wcslen(const wchar_t *s) +{ + const wchar_t *p = s; + size_t res = 0; + + assert(s != NULL); + + while (*p != L'\0'){ + p++; + res++; + } + + return res; +} diff --git a/lib/libc/wchar/wcsncasecmp.c b/lib/libc/wchar/wcsncasecmp.c new file mode 100644 index 000000000..98a3f1429 --- /dev/null +++ b/lib/libc/wchar/wcsncasecmp.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2006 Aleksey Cheusov + * + * This material is provided "as is", with absolutely no warranty expressed + * or implied. Any use is at your own risk. + * + * Permission to use or copy this software for any purpose is hereby granted + * without fee. Permission to modify the code and to distribute modified + * code is also granted without any restrictions. + */ + +#include +#include +#include + +int +wcsncasecmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + int lc1 = 0; + int lc2 = 0; + int diff = 0; + + assert(s1); + assert(s2); + + while (n--) { + lc1 = towlower (*s1); + lc2 = towlower (*s2); + + diff = lc1 - lc2; + if (diff) + return diff; + + if (!lc1) + return 0; + + ++s1; + ++s2; + } + + return 0; +} diff --git a/lib/libc/wchar/wcsncat.c b/lib/libc/wchar/wcsncat.c new file mode 100644 index 000000000..55efe6e39 --- /dev/null +++ b/lib/libc/wchar/wcsncat.c @@ -0,0 +1,53 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcsncat.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#include + +wchar_t * +wcsncat(wchar_t *s1, const wchar_t *s2, size_t n) +{ + wchar_t *p; + wchar_t *q; + const wchar_t *r; + + assert(s1 != NULL); + assert(s2 != NULL); + + p = s1; + while (*p) + p++; + q = p; + r = s2; + while (*r && n) { + *q++ = *r++; + n--; + } + *q = '\0'; + return s1; +} diff --git a/lib/libc/wchar/wcsncmp.c b/lib/libc/wchar/wcsncmp.c new file mode 100644 index 000000000..7ee23ab0c --- /dev/null +++ b/lib/libc/wchar/wcsncmp.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1989, 1993 + * The Regents of the University of California. 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. + * 3. 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. + */ + +#include +#include + +int +wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + + assert(s1 != NULL); + assert(s2 != NULL); + + if (n == 0) + return (0); + do { + if (*s1 != *s2++) { + /* XXX assumes wchar_t = int */ + return (*s1 - *--s2); + } + if (*s1++ == 0) + break; + } while (--n != 0); + return (0); +} diff --git a/lib/libc/wchar/wcsncpy.c b/lib/libc/wchar/wcsncpy.c new file mode 100644 index 000000000..e41a79066 --- /dev/null +++ b/lib/libc/wchar/wcsncpy.c @@ -0,0 +1,50 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcsncpy.c,v 1.1 1999/12/29 21:47:45 tshiozak Exp + */ + +#include +#include + +wchar_t * +wcsncpy(wchar_t *s1, const wchar_t *s2, size_t n) +{ + wchar_t *p = s1; + + assert(s1 != NULL); + assert(s2 != NULL); + + while (n>0 && *s2) { + *p++ = *s2++; + n--; + } + while (n>0) { + *p++ = L'\0'; + n--; + } + + return s1; +} diff --git a/lib/libc/wchar/wcspbrk.c b/lib/libc/wchar/wcspbrk.c new file mode 100644 index 000000000..02b3844c5 --- /dev/null +++ b/lib/libc/wchar/wcspbrk.c @@ -0,0 +1,52 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcspbrk.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include +#include + +wchar_t * +wcspbrk(const wchar_t *s, const wchar_t *set) +{ + const wchar_t *p; + const wchar_t *q; + + assert(s != NULL); + assert(set != NULL); + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) + return (wchar_t *) p; + q++; + } + p++; + } + return NULL; +} diff --git a/lib/libc/wchar/wcsrchr.c b/lib/libc/wchar/wcsrchr.c new file mode 100644 index 000000000..8ca87877b --- /dev/null +++ b/lib/libc/wchar/wcsrchr.c @@ -0,0 +1,48 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcsrchr.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include +#include + +wchar_t * +wcsrchr(const wchar_t *s, wchar_t c) +{ + const wchar_t *p; + + assert(s != NULL); + + p = s; + while (*p) + p++; + while (s <= p) { + if (*p == c) + return (wchar_t *) p; + p--; + } + return NULL; +} diff --git a/lib/libc/wchar/wcsspn.c b/lib/libc/wchar/wcsspn.c new file mode 100644 index 000000000..31c3796c9 --- /dev/null +++ b/lib/libc/wchar/wcsspn.c @@ -0,0 +1,56 @@ +/*- + * Copyright (c)1999,2001 Citrus Project, + * 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. + * + * $Citrus: xpg4dl/FreeBSD/lib/libc/string/wcsspn.c,v 1.3 2001/09/21 16:06:43 yamt Exp $ + */ + +#include +#include + +size_t +wcsspn(const wchar_t *s, const wchar_t *set) +{ + const wchar_t *p; + const wchar_t *q; + + assert(s != NULL); + assert(set != NULL); + + p = s; + while (*p) { + q = set; + while (*q) { + if (*p == *q) + break; + q++; + } + if (!*q) + goto done; + p++; + } + +done: + return (p - s); +} diff --git a/lib/libc/wchar/wcsstr.c b/lib/libc/wchar/wcsstr.c new file mode 100644 index 000000000..41bd18f2a --- /dev/null +++ b/lib/libc/wchar/wcsstr.c @@ -0,0 +1,67 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wcsstr.c,v 1.2 2000/12/21 05:07:25 itojun Exp + */ + +#include +#include + +wchar_t * +#ifdef WCSWCS +wcswcs(const wchar_t *big, const wchar_t *little) +#else +wcsstr(const wchar_t *big, const wchar_t *little) +#endif +{ + const wchar_t *p; + const wchar_t *q; + const wchar_t *r; + + assert(big != NULL); + assert(little != NULL); + + if (!*little) + return (wchar_t *) big; + if (wcslen(big) < wcslen(little)) + return NULL; + + p = big; + q = little; + while (*p) { + q = little; + r = p; + while (*q) { + if (*r != *q) + break; + q++; + r++; + } + if (!*q) + return (wchar_t *) p; + p++; + } + return NULL; +} diff --git a/lib/libc/wchar/wcstok.c b/lib/libc/wchar/wcstok.c new file mode 100644 index 000000000..8b5fd3704 --- /dev/null +++ b/lib/libc/wchar/wcstok.c @@ -0,0 +1,94 @@ +/*- + * Copyright (c) 1998 Softweyr LLC. All rights reserved. + * + * strtok_r, from Berkeley strtok + * Oct 13, 1998 by Wes Peters + * + * Copyright (c) 1988, 1993 + * The Regents of the University of California. 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 + * notices, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notices, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Softweyr LLC, the + * University of California, Berkeley, and its contributors. + * 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 SOFTWEYR LLC, 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 SOFTWEYR LLC, 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. + * + * Original version ID: + * FreeBSD: src/lib/libc/string/wcstok.c,v 1.1 2002/09/07 08:16:57 tjr Exp + */ + +#include +#include + +wchar_t * +wcstok(wchar_t *s, const wchar_t *delim, wchar_t **last) +{ + const wchar_t *spanp; + wchar_t c, sc; + wchar_t *tok; + + /* s may be NULL */ + assert(delim != NULL); + assert(last != NULL); + + if (s == NULL && (s = *last) == NULL) + return (NULL); + + /* + * Skip (span) leading delimiters (s += wcsspn(s, delim), sort of). + */ +cont: + c = *s++; + for (spanp = delim; (sc = *spanp++) != L'\0';) { + if (c == sc) + goto cont; + } + + if (c == L'\0') { /* no non-delimiter characters */ + *last = NULL; + return (NULL); + } + tok = s - 1; + + /* + * Scan token (scan for delimiters: s += wcscspn(s, delim), sort of). + * Note that delim must have one NUL; we stop if we see that, too. + */ + for (;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == L'\0') + s = NULL; + else + s[-1] = L'\0'; + *last = s; + return (tok); + } + } while (sc != L'\0'); + } + /* NOTREACHED */ +} diff --git a/lib/libc/wchar/wcstombs.c b/lib/libc/wchar/wcstombs.c new file mode 100644 index 000000000..97e5f8fa6 --- /dev/null +++ b/lib/libc/wchar/wcstombs.c @@ -0,0 +1,20 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Header$ */ + +#include +#include + +size_t +wcstombs(register char *s, register const wchar_t *pwcs, size_t n) +{ + register int i = n; + + while (--i >= 0) { + if (!(*s++ = *pwcs++)) + break; + } + return n - i - 1; +} diff --git a/lib/libc/wchar/wcswcs.c b/lib/libc/wchar/wcswcs.c new file mode 100644 index 000000000..4a346bd25 --- /dev/null +++ b/lib/libc/wchar/wcswcs.c @@ -0,0 +1,2 @@ +#define WCSWCS +#include "wcsstr.c" diff --git a/lib/libc/wchar/wctomb.c b/lib/libc/wchar/wctomb.c new file mode 100644 index 000000000..1afc0c562 --- /dev/null +++ b/lib/libc/wchar/wctomb.c @@ -0,0 +1,19 @@ +/* + * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. + * See the copyright notice in the ACK home directory, in the file "Copyright". + */ +/* $Header$ */ + +#include + +int +/* was: wctomb(char *s, wchar_t wchar) + * This conflicts with prototype, so it was changed to: + */ +wctomb(char *s, wchar_t wchar) +{ + if (!s) return 0; /* no state dependent codings */ + + *s = wchar; + return 1; +} diff --git a/lib/libc/wchar/wmemchr.c b/lib/libc/wchar/wmemchr.c new file mode 100644 index 000000000..424a553ba --- /dev/null +++ b/lib/libc/wchar/wmemchr.c @@ -0,0 +1,45 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wmemchr.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include + +wchar_t * +wmemchr(const wchar_t *s, wchar_t c, size_t n) +{ + size_t i; + + assert(s != NULL); + + for (i = 0; i < n; i++) { + if (*s == c) + return (wchar_t *) s; + s++; + } + return NULL; +} diff --git a/lib/libc/wchar/wmemcmp.c b/lib/libc/wchar/wmemcmp.c new file mode 100644 index 000000000..3e1ffcfd5 --- /dev/null +++ b/lib/libc/wchar/wmemcmp.c @@ -0,0 +1,49 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wmemcmp.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include + +int +wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n) +{ + size_t i; + + assert(s1 != NULL); + assert(s2 != NULL); + + for (i = 0; i < n; i++) { + if (*s1 != *s2) { + /* wchar might be unsigned */ + return (*s1 > *s2) ? 1 : -1; + } + s1++; + s2++; + } + return 0; +} diff --git a/lib/libc/wchar/wmemcpy.c b/lib/libc/wchar/wmemcpy.c new file mode 100644 index 000000000..f76d98fa7 --- /dev/null +++ b/lib/libc/wchar/wmemcpy.c @@ -0,0 +1,40 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wmemcpy.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include +#include + +wchar_t * +wmemcpy(wchar_t *d, const wchar_t *s, size_t n) +{ + assert(d != NULL); + assert(s != NULL); + + return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t)); +} diff --git a/lib/libc/wchar/wmemmove.c b/lib/libc/wchar/wmemmove.c new file mode 100644 index 000000000..445c2d5d2 --- /dev/null +++ b/lib/libc/wchar/wmemmove.c @@ -0,0 +1,40 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wmemmove.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include +#include + +wchar_t * +wmemmove(wchar_t *d, const wchar_t *s, size_t n) +{ + assert(d != NULL); + assert(s != NULL); + + return (wchar_t *)memmove(d, s, n * sizeof(wchar_t)); +} diff --git a/lib/libc/wchar/wmemset.c b/lib/libc/wchar/wmemset.c new file mode 100644 index 000000000..a41469f0f --- /dev/null +++ b/lib/libc/wchar/wmemset.c @@ -0,0 +1,46 @@ +/*- + * Copyright (c)1999 Citrus Project, + * 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. + * + * citrus Id: wmemset.c,v 1.2 2000/12/20 14:08:31 itojun Exp + */ + +#include +#include + +wchar_t * +wmemset(wchar_t *s, wchar_t c, size_t n) +{ + size_t i; + wchar_t *p; + + assert(s != NULL); + + p = (wchar_t *)s; + for (i = 0; i < n; i++) { + *p = c; + p++; + } + return s; +} diff --git a/servers/inet/generic/ip_read.c b/servers/inet/generic/ip_read.c index 5d88d9b05..67fe32f22 100644 --- a/servers/inet/generic/ip_read.c +++ b/servers/inet/generic/ip_read.c @@ -19,8 +19,8 @@ Copyright 1995 Philip Homburg THIS_FILE -FORWARD ip_ass_t *find_ass_ent ARGS(( ip_port_t *ip_port, U16_t id, - int proto, ipaddr_t src, ipaddr_t dst )); +FORWARD ip_ass_t *find_ass_ent ARGS(( ip_port_t *ip_port, u16_t id, + ipproto_t proto, ipaddr_t src, ipaddr_t dst )); FORWARD acc_t *merge_frags ARGS(( acc_t *first, acc_t *second )); FORWARD int ip_frag_chk ARGS(( acc_t *pack )); FORWARD acc_t *reassemble ARGS(( ip_port_t *ip_port, acc_t *pack, @@ -238,12 +238,8 @@ assert (first_hdr_size + first_datasize == bf_bufsize(first)); return first; } -PRIVATE ip_ass_t *find_ass_ent (ip_port, id, proto, src, dst) -ip_port_t *ip_port; -u16_t id; -ipproto_t proto; -ipaddr_t src; -ipaddr_t dst; +PRIVATE ip_ass_t *find_ass_ent ARGS(( ip_port_t *ip_port, u16_t id, + ipproto_t proto, ipaddr_t src, ipaddr_t dst )) { ip_ass_t *new_ass_ent, *tmp_ass_ent; int i; -- 2.44.0