46a06cd8e38392b5b155d24e5349afb18c7b610f
[reactos.git] / reactos / sdk / lib / crt / string / strtok_s.c
1 /* Taken from Wine Staging msvcrt/string.c */
2
3 #include <precomp.h>
4 #include <internal/wine/msvcrt.h>
5
6 /*********************************************************************
7 * strtok_s (MSVCRT.@)
8 */
9 char * CDECL strtok_s(char *str, const char *delim, char **ctx)
10 {
11 if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL;
12 if (!MSVCRT_CHECK_PMT(ctx != NULL)) return NULL;
13 if (!MSVCRT_CHECK_PMT(str != NULL || *ctx != NULL)) return NULL;
14
15 if(!str)
16 str = *ctx;
17
18 while(*str && strchr(delim, *str))
19 str++;
20 if(!*str)
21 return NULL;
22
23 *ctx = str+1;
24 while(**ctx && !strchr(delim, **ctx))
25 (*ctx)++;
26 if(**ctx)
27 *(*ctx)++ = 0;
28
29 return str;
30 }