Add implementation for strtok_r
This commit is contained in:
parent
cbd6cab28b
commit
e3eb9612af
|
@ -37,6 +37,7 @@ int strspn(const char *s , const char *charset);
|
||||||
int strcspn(const char *s , const char *charset);
|
int strcspn(const char *s , const char *charset);
|
||||||
char *strsep(char **stringp, const char *delim);
|
char *strsep(char **stringp, const char *delim);
|
||||||
char *strtok(char *str, const char *sep);
|
char *strtok(char *str, const char *sep);
|
||||||
|
char* strtok_r(char *str, const char *delim, char **nextp);
|
||||||
char *strstr(const char *big , const char *little);
|
char *strstr(const char *big , const char *little);
|
||||||
char *strcasestr(const char *big, const char *little);
|
char *strcasestr(const char *big, const char *little);
|
||||||
char *strlwr(char *string);
|
char *strlwr(char *string);
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
*
|
*
|
||||||
* Part of the PSXSDK C library
|
* Part of the PSXSDK C library
|
||||||
*/
|
*/
|
||||||
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -439,6 +439,50 @@ char *strsep(char **stringp, const char *delim)
|
||||||
return old;
|
return old;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* public domain strtok_r() by Charlie Gordon
|
||||||
|
*
|
||||||
|
* from comp.lang.c 9/14/2007
|
||||||
|
*
|
||||||
|
* http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
|
||||||
|
*
|
||||||
|
* (Declaration that it's public domain):
|
||||||
|
* http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
|
||||||
|
*/
|
||||||
|
|
||||||
|
char* strtok_r(
|
||||||
|
char *str,
|
||||||
|
const char *delim,
|
||||||
|
char **nextp)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
|
||||||
|
if (str == NULL)
|
||||||
|
{
|
||||||
|
str = *nextp;
|
||||||
|
}
|
||||||
|
|
||||||
|
str += strspn(str, delim);
|
||||||
|
|
||||||
|
if (*str == '\0')
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = str;
|
||||||
|
|
||||||
|
str += strcspn(str, delim);
|
||||||
|
|
||||||
|
if (*str)
|
||||||
|
{
|
||||||
|
*str++ = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
*nextp = str;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
char *strtok(char *str, const char *sep)
|
char *strtok(char *str, const char *sep)
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
|
|
Loading…
Reference in New Issue