xref: /haiku/src/system/libroot/posix/wchar/wcsdup.c (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2 ** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 
6 #include <stdlib.h>
7 #include <string.h>
8 
9 #include <errno_private.h>
10 #include <wchar_private.h>
11 
12 
13 wchar_t*
14 __wcsdup(const wchar_t* wcs)
15 {
16 	if (wcs == NULL)
17 		return NULL;
18 
19 	{
20 		size_t bufferSize = (wcslen(wcs) + 1) * sizeof(wchar_t);
21 		wchar_t* dest = malloc(bufferSize);
22 		if (dest == NULL) {
23 			__set_errno(ENOMEM);
24 			return NULL;
25 		}
26 
27 		memcpy(dest, wcs, bufferSize);
28 
29 		return dest;
30 	}
31 }
32 
33 
34 B_DEFINE_WEAK_ALIAS(__wcsdup, wcsdup);
35