xref: /netbsd-src/lib/libc/string/wcsdup.c (revision 54097ce7af2a6f6914ccd016c860ec1acb60f40b)
1*54097ce7Schristos /*	$NetBSD: wcsdup.c,v 1.1 2006/08/22 20:50:46 christos Exp $	*/
2*54097ce7Schristos 
3*54097ce7Schristos #include <sys/cdefs.h>
4*54097ce7Schristos 
5*54097ce7Schristos #if defined(LIBC_SCCS) && !defined(lint)
6*54097ce7Schristos __RCSID("$NetBSD: wcsdup.c,v 1.1 2006/08/22 20:50:46 christos Exp $");
7*54097ce7Schristos #endif /* LIBC_SCCS and not lint */
8*54097ce7Schristos 
9*54097ce7Schristos #include "namespace.h"
10*54097ce7Schristos #include <stdlib.h>
11*54097ce7Schristos #include <assert.h>
12*54097ce7Schristos #include <string.h>
13*54097ce7Schristos #include <wchar.h>
14*54097ce7Schristos 
15*54097ce7Schristos __weak_alias(wcsdup,_wcsdup)
16*54097ce7Schristos 
17*54097ce7Schristos wchar_t *
18*54097ce7Schristos wcsdup(const wchar_t *str)
19*54097ce7Schristos {
20*54097ce7Schristos 	wchar_t *copy;
21*54097ce7Schristos 	size_t len;
22*54097ce7Schristos 
23*54097ce7Schristos 	_DIAGASSERT(str != NULL);
24*54097ce7Schristos 
25*54097ce7Schristos 	len = wcslen(str) + 1;
26*54097ce7Schristos 	copy = malloc(len * sizeof (wchar_t));
27*54097ce7Schristos 
28*54097ce7Schristos 	if (!copy)
29*54097ce7Schristos 		return NULL;
30*54097ce7Schristos 
31*54097ce7Schristos 	return wmemcpy(copy, str, len);
32*54097ce7Schristos }
33