This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH]: New function wcsdup


Hi,

wcsdup is required by POSIX-1.2008.  I applied the below patch to
add this function to newlib.

Jeff, I have no idea where to look for the ELIX levels.  I added
wcscpy to ELIX_LEVEL_2 by way of guessing.


Corinna


	* 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.


Index: libc/include/wchar.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/wchar.h,v
retrieving revision 1.26
diff -u -p -r1.26 wchar.h
--- libc/include/wchar.h	11 Mar 2009 12:57:53 -0000	1.26
+++ libc/include/wchar.h	15 Mar 2009 13:33:57 -0000
@@ -72,6 +72,8 @@ int	_EXFUN(wcscmp, (const wchar_t *, con
 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));
Index: libc/string/Makefile.am
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/Makefile.am,v
retrieving revision 1.23
diff -u -p -r1.23 Makefile.am
--- libc/string/Makefile.am	11 Mar 2009 12:57:53 -0000	1.23
+++ libc/string/Makefile.am	15 Mar 2009 13:33:58 -0000
@@ -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
 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  \
Index: libc/string/strings.tex
===================================================================
RCS file: /cvs/src/src/newlib/libc/string/strings.tex,v
retrieving revision 1.10
diff -u -p -r1.10 strings.tex
--- libc/string/strings.tex	11 Mar 2009 12:57:53 -0000	1.10
+++ libc/string/strings.tex	15 Mar 2009 13:33:58 -0000
@@ -47,6 +47,7 @@ managing areas of memory.  The correspon
 * 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
 
@@ -174,4 +175,7 @@ managing areas of memory.  The correspon
 @include string/wcscasecmp.def
 
 @page
+@include string/wcsdup.def
+
+@page
 @include string/wcsncasecmp.def
Index: libc/string/wcsdup.c
===================================================================
RCS file: libc/string/wcsdup.c
diff -N libc/string/wcsdup.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ libc/string/wcsdup.c	15 Mar 2009 13:33:58 -0000
@@ -0,0 +1,62 @@
+/*
+FUNCTION
+	<<wcsdup>>---wide character string duplicate
+	
+INDEX
+	wcsdup
+INDEX
+	_wcsdup_r
+
+ANSI_SYNOPSIS
+	#include <wchar.h>
+	wchar_t *wcsdup(const wchar_t *<[str]>);
+
+	#include <wchar.h>
+	wchar_t *_wcsdup_r(struct _reent *<ptr>, const wchar_t *<[str]>);
+
+TRAD_SYNOPSIS
+	#include <wchar.h>
+	wchar_t *wcsdup(<ptr>, <[str]>)
+	struct _reent *<ptr>;
+	wchar_t *<[str]>;
+
+DESCRIPTION
+	<<wcsdup>> allocates a new wide character string using <<malloc>,
+	and copies the content of the argument <[str]> into the newly
+	allocated string, thus making a copy of <[str]>.
+
+RETURNS 
+	<<wcsdup>> 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 <reent.h>
+#include <stdlib.h>
+#include <wchar.h>
+
+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 */



-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]