vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / wchar / wcsdup.c
blobf274b92e4055d60222b14f7a9476cb9f4341c947
1 /*
2 ** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
6 #include <stdlib.h>
7 #include <string.h>
9 #include <errno_private.h>
10 #include <wchar_private.h>
13 wchar_t*
14 __wcsdup(const wchar_t* wcs)
16 if (wcs == NULL)
17 return NULL;
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;
27 memcpy(dest, wcs, bufferSize);
29 return dest;
34 B_DEFINE_WEAK_ALIAS(__wcsdup, wcsdup);