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