1 /* Copyright (c) 2009 Corinna Vinschen <corinna@vinschen.de> */
2 /*
3 FUNCTION
4 	<<wcsdup>>---wide character string duplicate
5 
6 INDEX
7 	wcsdup
8 INDEX
9 	_wcsdup_r
10 
11 SYNOPSIS
12 	#include <wchar.h>
13 	wchar_t *wcsdup(const wchar_t *<[str]>);
14 
15 	#include <wchar.h>
16 	wchar_t *_wcsdup_r(struct _reent *<[ptr]>, const wchar_t *<[str]>);
17 
18 DESCRIPTION
19 	<<wcsdup>> allocates a new wide character string using <<malloc>>,
20 	and copies the content of the argument <[str]> into the newly
21 	allocated string, thus making a copy of <[str]>.
22 
23 RETURNS
24 	<<wcsdup>> returns a pointer to the copy of <[str]> if enough
25 	memory for the copy was available.  Otherwise it returns NULL
26 	and errno is set to ENOMEM.
27 
28 PORTABILITY
29 POSIX-1.2008
30 
31 QUICKREF
32 	wcsdup
33 */
34 
35 #include <stdlib.h>
36 #include <wchar.h>
37 
38 #ifndef _REENT_ONLY
39 
40 wchar_t *
wcsdup(const wchar_t * str)41 wcsdup (const wchar_t *str)
42 {
43   size_t len = wcslen (str) + 1;
44   wchar_t *copy = malloc (len * sizeof (wchar_t));
45   if (copy)
46     wmemcpy (copy, str, len);
47   return copy;
48 }
49 
50 #endif /* !_REENT_ONLY */
51