From 159a17c8c800f24e82ddd60ed103a76c6f275408 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Sun, 15 Mar 2009 13:39:07 +0000 Subject: [PATCH] * libc/include/wchar.h (wcsdup, _wcsdup_r): Declare. * libc/string/Makefile.am: Add wcsdup.c. * libc/string/Makefile.in: Regenerate. * libc/string/strings.tex: Add wcsdup documentation reference. * libc/string/wcsdup.c: New file. --- newlib/ChangeLog | 8 +++++ newlib/libc/include/wchar.h | 2 ++ newlib/libc/string/Makefile.am | 5 +-- newlib/libc/string/Makefile.in | 16 ++++++--- newlib/libc/string/strings.tex | 4 +++ newlib/libc/string/wcsdup.c | 62 ++++++++++++++++++++++++++++++++++ 6 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 newlib/libc/string/wcsdup.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index f5bbe69af..da66a50b9 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,11 @@ +2009-03-15 Corinna Vinschen + + * libc/include/wchar.h (wcsdup, _wcsdup_r): Declare. + * libc/string/Makefile.am: Add wcsdup.c. + * libc/string/Makefile.in: Regenerate. + * libc/string/strings.tex: Add wcsdup documentation reference. + * libc/string/wcsdup.c: New file. + 2009-03-14 Corinna Vinschen * libc/include/stdlib.h (_mkstemp_r, _mktemp_r): Move out of diff --git a/newlib/libc/include/wchar.h b/newlib/libc/include/wchar.h index 3dc847b22..252e59d81 100644 --- a/newlib/libc/include/wchar.h +++ b/newlib/libc/include/wchar.h @@ -72,6 +72,8 @@ int _EXFUN(wcscmp, (const wchar_t *, const wchar_t *)); int _EXFUN(wcscoll, (const wchar_t *, const wchar_t *)); wchar_t *_EXFUN(wcscpy, (wchar_t * , const wchar_t *)); wchar_t *_EXFUN(wcpcpy, (wchar_t * , const wchar_t *)); +wchar_t *_EXFUN(wcsdup, (const wchar_t *)); +wchar_t *_EXFUN(_wcsdup_r, (struct _reent *, const wchar_t * )); size_t _EXFUN(wcscspn, (const wchar_t *, const wchar_t *)); size_t _EXFUN(wcsftime, (wchar_t *, size_t, const wchar_t *, const struct tm *)); size_t _EXFUN(wcslcat, (wchar_t *, const wchar_t *, size_t)); diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index 6e630d3d3..8bdef3be0 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -85,7 +85,8 @@ ELIX_2_SOURCES = \ strcasestr.c \ strndup_r.c \ wcpcpy.c \ - wcpncpy.c + wcpncpy.c \ + wcsdup.c endif !ELIX_LEVEL_1 if ELIX_LEVEL_1 @@ -130,7 +131,7 @@ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \ memccpy.def mempcpy.def stpcpy.def stpncpy.def \ wcscasecmp.def wcscat.def wcschr.def wcscmp.def wcscoll.def \ -wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def \ +wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def wcsdup \ wcslcat.def wcslcpy.def wcslen.def wcsncasecmp.def wcsncat.def \ wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \ wcsrchr.def wcsspn.def wcsstr.def wcstok.def \ diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index c28d000d6..a3b409477 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -100,7 +100,8 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-strcasestr.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-strndup_r.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-wcpcpy.$(OBJEXT) \ -@ELIX_LEVEL_1_FALSE@ lib_a-wcpncpy.$(OBJEXT) +@ELIX_LEVEL_1_FALSE@ lib_a-wcpncpy.$(OBJEXT) \ +@ELIX_LEVEL_1_FALSE@ lib_a-wcsdup.$(OBJEXT) @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_3 = lib_a-memmem.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-wcscasecmp.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ lib_a-wcsncasecmp.$(OBJEXT) @@ -125,7 +126,7 @@ am__objects_4 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \ @ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \ @ELIX_LEVEL_1_FALSE@ stpcpy.lo stpncpy.lo strndup.lo \ @ELIX_LEVEL_1_FALSE@ strcasestr.lo strndup_r.lo wcpcpy.lo \ -@ELIX_LEVEL_1_FALSE@ wcpncpy.lo +@ELIX_LEVEL_1_FALSE@ wcpncpy.lo wcsdup.lo @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@am__objects_6 = memmem.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wcscasecmp.lo \ @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ wcsncasecmp.lo @@ -391,7 +392,8 @@ GENERAL_SOURCES = \ @ELIX_LEVEL_1_FALSE@ strcasestr.c \ @ELIX_LEVEL_1_FALSE@ strndup_r.c \ @ELIX_LEVEL_1_FALSE@ wcpcpy.c \ -@ELIX_LEVEL_1_FALSE@ wcpncpy.c +@ELIX_LEVEL_1_FALSE@ wcpncpy.c \ +@ELIX_LEVEL_1_FALSE@ wcsdup.c @ELIX_LEVEL_1_TRUE@ELIX_2_SOURCES = @ELIX_LEVEL_1_FALSE@@ELIX_LEVEL_2_FALSE@@ELIX_LEVEL_3_FALSE@ELIX_4_SOURCES = \ @@ -420,7 +422,7 @@ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \ memccpy.def mempcpy.def stpcpy.def stpncpy.def \ wcscasecmp.def wcscat.def wcschr.def wcscmp.def wcscoll.def \ -wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def \ +wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def wcsdup \ wcslcat.def wcslcpy.def wcslen.def wcsncasecmp.def wcsncat.def \ wcsncmp.def wcsncpy.def wcsnlen.def wcspbrk.def \ wcsrchr.def wcsspn.def wcsstr.def wcstok.def \ @@ -955,6 +957,12 @@ lib_a-wcpncpy.o: wcpncpy.c lib_a-wcpncpy.obj: wcpncpy.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcpncpy.obj `if test -f 'wcpncpy.c'; then $(CYGPATH_W) 'wcpncpy.c'; else $(CYGPATH_W) '$(srcdir)/wcpncpy.c'; fi` +lib_a-wcsdup.o: wcsdup.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcsdup.o `test -f 'wcsdup.c' || echo '$(srcdir)/'`wcsdup.c + +lib_a-wcsdup.obj: wcsdup.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-wcsdup.obj `if test -f 'wcsdup.c'; then $(CYGPATH_W) 'wcsdup.c'; else $(CYGPATH_W) '$(srcdir)/wcsdup.c'; fi` + lib_a-memmem.o: memmem.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-memmem.o `test -f 'memmem.c' || echo '$(srcdir)/'`memmem.c diff --git a/newlib/libc/string/strings.tex b/newlib/libc/string/strings.tex index 0ad6137b6..2e2c7fd73 100644 --- a/newlib/libc/string/strings.tex +++ b/newlib/libc/string/strings.tex @@ -47,6 +47,7 @@ managing areas of memory. The corresponding declarations are in * strxfrm:: Transform string * swab:: Swap adjacent bytes * wcscasecmp:: Compare wide character strings ignoring case +* wcsdup:: Wide character string duplicate * wcsncasecmp:: Compare wide character strings ignoring case @end menu @@ -173,5 +174,8 @@ managing areas of memory. The corresponding declarations are in @page @include string/wcscasecmp.def +@page +@include string/wcsdup.def + @page @include string/wcsncasecmp.def diff --git a/newlib/libc/string/wcsdup.c b/newlib/libc/string/wcsdup.c new file mode 100644 index 000000000..8462c0b09 --- /dev/null +++ b/newlib/libc/string/wcsdup.c @@ -0,0 +1,62 @@ +/* +FUNCTION + <>---wide character string duplicate + +INDEX + wcsdup +INDEX + _wcsdup_r + +ANSI_SYNOPSIS + #include + wchar_t *wcsdup(const wchar_t *<[str]>); + + #include + wchar_t *_wcsdup_r(struct _reent *, const wchar_t *<[str]>); + +TRAD_SYNOPSIS + #include + wchar_t *wcsdup(, <[str]>) + struct _reent *; + wchar_t *<[str]>; + +DESCRIPTION + <> allocates a new wide character string using <, + and copies the content of the argument <[str]> into the newly + allocated string, thus making a copy of <[str]>. + +RETURNS + <> returns a pointer to the copy of <[str]> if enough + memory for the copy was available. Otherwise it returns NULL + and errno is set to ENOMEM. + +PORTABILITY +POSIX-1.2008 + +QUICKREF + wcsdup +*/ + +#include +#include +#include + +wchar_t * +_wcsdup_r (struct _reent *p, const wchar_t *str) +{ + size_t len = wcslen (str) + 1; + wchar_t *copy = _malloc_r (p, len * sizeof (wchar_t)); + if (copy) + wmemcpy (copy, str, len); + return copy; +} + +#ifndef _REENT_ONLY + +wchar_t * +wcsdup (const wchar_t *str) +{ + return _wcsdup_r (_REENT, str); +} + +#endif /* !_REENT_ONLY */