vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / wchar / wcstok.c
blob4880db95dcc41e13bd19a82e9e6269390b933468
1 /*
2 ** Copyright 2001, Travis Geiselbrecht.
3 ** Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de>
4 ** All rights reserved. Distributed under the terms of the NewOS License.
5 */
8 #include <wchar_private.h>
11 wchar_t *
12 __wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** savePtr)
14 wchar_t *wcsBegin, *wcsEnd;
16 if (wcs == NULL && savePtr == NULL)
17 return NULL;
19 wcsBegin = wcs ? wcs : *savePtr;
20 if (wcsBegin == NULL)
21 return NULL;
23 wcsBegin += wcsspn(wcsBegin, delim);
24 if (*wcsBegin == '\0') {
25 if (savePtr)
26 *savePtr = NULL;
27 return NULL;
30 wcsEnd = wcspbrk(wcsBegin, delim);
31 if (wcsEnd && *wcsEnd != '\0')
32 *wcsEnd++ = '\0';
33 if (savePtr)
34 *savePtr = wcsEnd;
36 return wcsBegin;
40 B_DEFINE_WEAK_ALIAS(__wcstok, wcstok);