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 */ 6 7 8 #include <wchar_private.h> 9 10 11 wchar_t * 12 __wcstok(wchar_t* wcs, const wchar_t* delim, wchar_t** savePtr) 13 { 14 wchar_t *wcsBegin, *wcsEnd; 15 16 if (wcs == NULL && savePtr == NULL) 17 return NULL; 18 19 wcsBegin = wcs ? wcs : *savePtr; 20 if (wcsBegin == NULL) 21 return NULL; 22 23 wcsBegin += wcsspn(wcsBegin, delim); 24 if (*wcsBegin == '\0') { 25 if (savePtr) 26 *savePtr = NULL; 27 return NULL; 28 } 29 30 wcsEnd = wcspbrk(wcsBegin, delim); 31 if (wcsEnd && *wcsEnd != '\0') 32 *wcsEnd++ = '\0'; 33 if (savePtr) 34 *savePtr = wcsEnd; 35 36 return wcsBegin; 37 } 38 39 40 B_DEFINE_WEAK_ALIAS(__wcstok, wcstok); 41