diff --git a/libpsx/include/string.h b/libpsx/include/string.h index 2c232fa..a5dd114 100644 --- a/libpsx/include/string.h +++ b/libpsx/include/string.h @@ -37,6 +37,7 @@ int strspn(const char *s , const char *charset); int strcspn(const char *s , const char *charset); char *strsep(char **stringp, const char *delim); 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 *strcasestr(const char *big, const char *little); char *strlwr(char *string); diff --git a/libpsx/src/libc/string.c b/libpsx/src/libc/string.c index 2ab2f0b..791e1df 100644 --- a/libpsx/src/libc/string.c +++ b/libpsx/src/libc/string.c @@ -3,7 +3,7 @@ * * Part of the PSXSDK C library */ - +#include #include #include #include @@ -439,6 +439,50 @@ char *strsep(char **stringp, const char *delim) 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) { int x, y;