From 788d6cf3ad51c32588d7d46f1537a7f0ccba0943 Mon Sep 17 00:00:00 2001 From: jjohnstn Date: Thu, 23 Oct 2003 18:07:13 +0000 Subject: [PATCH] 2003-10-23 Artem B. Bityuckiy * libc/string/wcsnlen.c: New file. * libc/include/wchar.h: Add wcsnlen prototype. * libc/string/Makefile.am: Add wcsnlen support. * libc/string/Makefile.in: Regenerated. * libc/string/wcstrings.tex: Add wcsnlen documentation. --- newlib/ChangeLog | 8 +++++ newlib/libc/include/wchar.h | 1 + newlib/libc/string/Makefile.am | 12 ++++--- newlib/libc/string/Makefile.in | 33 ++++++++++-------- newlib/libc/string/wcsnlen.c | 74 ++++++++++++++++++++++++++++++++++++++++ newlib/libc/string/wcstrings.tex | 4 +++ 6 files changed, 113 insertions(+), 19 deletions(-) create mode 100644 newlib/libc/string/wcsnlen.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 0af6c34a6f..a579e43d70 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,11 @@ +2003-10-23 Artem B. Bityuckiy + + * libc/string/wcsnlen.c: New file. + * libc/include/wchar.h: Add wcsnlen prototype. + * libc/string/Makefile.am: Add wcsnlen support. + * libc/string/Makefile.in: Regenerated. + * libc/string/wcstrings.tex: Add wcsnlen documentation. + 2003-10-22 Richard Sandiford * libc/stdlib/exit.c (exit): Handle null _GLOBAL_REENT->_atexits. diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h index 8d3e4d9ee2..9e89537396 100644 --- a/newlib/libc/include/wchar.h +++ b/newlib/libc/include/wchar.h @@ -58,6 +58,7 @@ size_t _EXFUN(wcslen, (const wchar_t *)); wchar_t *_EXFUN(wcsncat, (wchar_t * , const wchar_t * , size_t)); int _EXFUN(wcsncmp, (const wchar_t *, const wchar_t *, size_t)); wchar_t *_EXFUN(wcsncpy, (wchar_t * , const wchar_t * , size_t)); +size_t _EXFUN(wcsnlen, (const wchar_t *, size_t)); wchar_t *_EXFUN(wcspbrk, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcsrchr, (const wchar_t *, wchar_t)); size_t _EXFUN(wcsspn, (const wchar_t *, const wchar_t *)); diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index 6066c9bbf6..cac5f1d539 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -57,6 +57,7 @@ GENERAL_SOURCES = \ wcsncat.c \ wcsncmp.c \ wcsncpy.c \ + wcsnlen.c \ wcspbrk.c \ wcsrchr.c \ wcsspn.c \ @@ -108,11 +109,12 @@ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strlwr.def strupr.def memccpy.def \ mempcpy.def \ wcscat.def wcschr.def wcscmp.def wcscoll.def \ -wcscpy.def wcscspn.def \ -wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ -wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ -wmemmove.def wmemset.def +wcscpy.def wcscspn.def \ +wcslcat.def wcslcpy.def wcslen.def wcsncat.def \ +wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \ +wcsrchr.def wcsspn.def wcsstr.def \ +wcswidth.def wcwidth.def wmemchr.def \ +wmemcmp.def wmemcpy.def wmemmove.def wmemset.def SUFFIXES = .def diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index b53356c9eb..87adac44b8 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -1,6 +1,6 @@ -# Makefile.in generated automatically by automake 1.4 from Makefile.am +# Makefile.in generated automatically by automake 1.4-p5 from Makefile.am -# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# Copyright (C) 1994, 1995-8, 1999, 2001 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -163,6 +163,7 @@ GENERAL_SOURCES = \ wcsncat.c \ wcsncmp.c \ wcsncpy.c \ + wcsnlen.c \ wcspbrk.c \ wcsrchr.c \ wcsspn.c \ @@ -206,11 +207,12 @@ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strlwr.def strupr.def memccpy.def \ mempcpy.def \ wcscat.def wcschr.def wcscmp.def wcscoll.def \ -wcscpy.def wcscspn.def \ -wcslcat.def wcslcpy.def wcslen.def wcsncat.def wcsncmp.def \ -wcsncpy.def wcspbrk.def wcsrchr.def wcsspn.def wcsstr.def \ -wcswidth.def wcwidth.def wmemchr.def wmemcmp.def wmemcpy.def \ -wmemmove.def wmemset.def +wcscpy.def wcscspn.def \ +wcslcat.def wcslcpy.def wcslen.def wcsncat.def \ +wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \ +wcsrchr.def wcsspn.def wcsstr.def \ +wcswidth.def wcwidth.def wmemchr.def \ +wmemcmp.def wmemcpy.def wmemmove.def wmemset.def SUFFIXES = .def @@ -248,10 +250,12 @@ LIBS = @LIBS@ @USE_LIBTOOL_FALSE@wcscpy.$(OBJEXT) wcscspn.$(OBJEXT) wcslcat.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcslcpy.$(OBJEXT) wcslen.$(OBJEXT) wcsncat.$(OBJEXT) \ @USE_LIBTOOL_FALSE@wcsncmp.$(OBJEXT) wcsncpy.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wcspbrk.$(OBJEXT) wcsrchr.$(OBJEXT) wcsspn.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wcsstr.$(OBJEXT) wcswidth.$(OBJEXT) wcwidth.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) wmemcpy.$(OBJEXT) \ -@USE_LIBTOOL_FALSE@wmemmove.$(OBJEXT) wmemset.$(OBJEXT) +@USE_LIBTOOL_FALSE@wcsnlen.$(OBJEXT) wcspbrk.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wcsrchr.$(OBJEXT) wcsspn.$(OBJEXT) wcsstr.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wcswidth.$(OBJEXT) wcwidth.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemchr.$(OBJEXT) wmemcmp.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemcpy.$(OBJEXT) wmemmove.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@wmemset.$(OBJEXT) LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@libstring_la_OBJECTS = bcopy.lo bzero.lo index.lo \ @@ -265,9 +269,10 @@ LTLIBRARIES = $(noinst_LTLIBRARIES) @USE_LIBTOOL_TRUE@strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo \ @USE_LIBTOOL_TRUE@wcscat.lo wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo \ @USE_LIBTOOL_TRUE@wcscspn.lo wcslcat.lo wcslcpy.lo wcslen.lo wcsncat.lo \ -@USE_LIBTOOL_TRUE@wcsncmp.lo wcsncpy.lo wcspbrk.lo wcsrchr.lo wcsspn.lo \ -@USE_LIBTOOL_TRUE@wcsstr.lo wcswidth.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ -@USE_LIBTOOL_TRUE@wmemcpy.lo wmemmove.lo wmemset.lo +@USE_LIBTOOL_TRUE@wcsncmp.lo wcsncpy.lo wcsnlen.lo wcspbrk.lo \ +@USE_LIBTOOL_TRUE@wcsrchr.lo wcsspn.lo wcsstr.lo wcswidth.lo wcwidth.lo \ +@USE_LIBTOOL_TRUE@wmemchr.lo wmemcmp.lo wmemcpy.lo wmemmove.lo \ +@USE_LIBTOOL_TRUE@wmemset.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/string/wcsnlen.c b/newlib/libc/string/wcsnlen.c new file mode 100644 index 0000000000..e84342d3dd --- /dev/null +++ b/newlib/libc/string/wcsnlen.c @@ -0,0 +1,74 @@ +/* +FUNCTION + <>---get fixed-size wide character string length + +INDEX + wcsnlen + +ANSI_SYNOPSIS + #include + size_t wcsnlen(const wchar_t *<[s]>, size_t <[maxlen]>); + +TRAD_SYNOPSIS + #include + size_t wcsnlen(<[s]>, <[maxlen]>) + wchar_t *<[s]>; + size_t <[maxlen]>; + +DESCRIPTION + The <> function computes the number of wide character codes + in the wide character string pointed to by <[s]> not including the + terminating L'\0' wide character but at most <[maxlen]> wide + characters. + +RETURNS + <> returns the length of <[s]> if it is less then <[maxlen]>, + or <[maxlen]> if there is no L'\0' wide character in first <[maxlen]> + characters. + +PORTABILITY +<> is GNU extension.. +<> requires no supporting OS subroutines. +*/ + +/* + * Copyright (c) 2003, Artem B. Bityuckiy (dedekind@mail.ru). + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the above copyright notice, + * this condition statement, and the following disclaimer are retained + * in any redistributions of the source code. + * + * 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 <_ansi.h> +#include +#include + +size_t +_DEFUN(wcsnlen, (s, maxlen), + _CONST wchar_t *s _AND + size_t maxlen) +{ + _CONST wchar_t *p; + + p = s; + while (*p && maxlen-- > 0) + p++; + + return (size_t)(p - s); +} + + + diff --git a/newlib/libc/string/wcstrings.tex b/newlib/libc/string/wcstrings.tex index 8f82e62c3d..ad0a607885 100644 --- a/newlib/libc/string/wcstrings.tex +++ b/newlib/libc/string/wcstrings.tex @@ -23,6 +23,7 @@ declarations are in @file{wchar.h}. * wcsncat:: Concatenate wide-character strings * wcsncmp:: Wide-character string compare * wcsncpy:: Counted copy wide-character string +* wcsnlen:: Wide-character string length with maximum limit * wcspbrk:: Find wide-chars in string * wcsrchr:: Reverse search for wide-character in string * wcsspn:: Find initial match in wide-character string @@ -83,6 +84,9 @@ declarations are in @file{wchar.h}. @include string/wcsncpy.def @page +@include string/wcsnlen.def + +@page @include string/wcspbrk.def @page -- 2.11.0