Microsoft might be trying to force you to use wsctok_s
instead of standard conforming but non-reentrant wsctok
, especially in device driver code linked with the Windows kernel.
If strtok_s
is missing too, it means the C library for kernel and driver development is incomplete. You are in a hosted environment, parts of the Standard C library may be missing.
Note that you are not using an old prototype for wcstok()
: Microsoft changed the prototype for wcstok
in its VisualStudio 2015 to bring it in conformance with the C Standard:
wchar_t *wcstok(wchar_t *restrict ws1, const wchar_t *restrict ws2,
wchar_t **restrict ptr);
It would be better to avoid using this function and change your code to use wcschr()
directly.
If wcschr
is missing too, use this simple implementation:
/* 7.29.4.5 Wide string search functions */
wchar_t *wcschr(const wchar_t *s, wchar_t c) {
for (;;) {
if (*s == c)
return (wchar_t *)s;
if (*s++ == L'\0')
return NULL;
}
}
Here is a standard conformant implementation of wcstok()
:
wchar_t *wcstok(wchar_t *restrict s1, const wchar_t *restrict s2,
wchar_t **restrict ptr) {
wchar_t *p;
if (s1 == NULL)
s1 = *ptr;
while (*s1 && wcschr(s2, *s1))
s1++;
if (!*s1) {
*ptr = s1;
return NULL;
}
for (p = s1; *s1 && !wcschr(s2, *s1); s1++)
continue;
if (*s1)
*s1++ = L'\0';
*ptr = s1;
return p;
}