Add thread-safe strtok_r() function.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9192 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
40cc0ebde2
commit
a889bb181d
@ -6,27 +6,38 @@
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static char *___strtok = NULL;
|
||||
|
||||
char *
|
||||
strtok(char *s, char const *ct)
|
||||
strtok_r(char *s, char const *ct, char **save_ptr)
|
||||
{
|
||||
char *sbegin, *send;
|
||||
|
||||
if (!s && !save_ptr)
|
||||
return NULL;
|
||||
|
||||
sbegin = s ? s : ___strtok;
|
||||
sbegin = s ? s : *save_ptr;
|
||||
if (!sbegin) {
|
||||
return NULL;
|
||||
}
|
||||
sbegin += strspn(sbegin,ct);
|
||||
if (*sbegin == '\0') {
|
||||
___strtok = NULL;
|
||||
if (save_ptr)
|
||||
*save_ptr = NULL;
|
||||
return NULL;
|
||||
}
|
||||
send = strpbrk(sbegin, ct);
|
||||
if (send && *send != '\0')
|
||||
*send++ = '\0';
|
||||
___strtok = send;
|
||||
if (save_ptr)
|
||||
*save_ptr = send;
|
||||
|
||||
return sbegin;
|
||||
}
|
||||
|
||||
char *
|
||||
strtok(char *s, char const *ct)
|
||||
{
|
||||
return strtok_r(s, ct, &___strtok);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user