vfs: check userland buffers before reading them.
[haiku.git] / src / system / libroot / posix / string / strtok.c
blob8c50f3393ce6e6f1d7463233b84b4b130244add1
1 /*
2 ** Copyright 2001, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
4 */
7 #include <sys/types.h>
8 #include <string.h>
11 static char *___strtok = NULL;
14 char *
15 strtok_r(char *s, char const *ct, char **save_ptr)
17 char *sbegin, *send;
19 if (!s && !save_ptr)
20 return NULL;
22 sbegin = s ? s : *save_ptr;
23 if (!sbegin)
24 return NULL;
26 sbegin += strspn(sbegin, ct);
27 if (*sbegin == '\0') {
28 if (save_ptr)
29 *save_ptr = NULL;
30 return NULL;
33 send = strpbrk(sbegin, ct);
34 if (send && *send != '\0')
35 *send++ = '\0';
36 if (save_ptr)
37 *save_ptr = send;
39 return sbegin;
43 char *
44 strtok(char *s, char const *ct)
46 return strtok_r(s, ct, &___strtok);