vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / wchar / wcpncpy.c
blob06604634b8da9936bccd5d40bdfac4719fa810d4
1 /*
2 ** Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de. All rights reserved.
3 ** Distributed under the terms of the Haiku License.
4 */
6 #include <wchar_private.h>
9 wchar_t*
10 __wcpncpy(wchar_t* dest, const wchar_t* src, size_t n)
12 const wchar_t* srcEnd = src + n;
13 wchar_t* destEnd = dest + n;
15 while (src < srcEnd && *src != L'\0')
16 *dest++ = *src++;
18 if (dest < destEnd) {
19 while (--destEnd >= dest)
20 *destEnd = L'\0';
23 return dest;
27 B_DEFINE_WEAK_ALIAS(__wcpncpy, wcpncpy);