Add implementation for strtok_r

This commit is contained in:
Xavier Del Campo Romero 2021-01-03 01:01:11 +01:00
parent cbd6cab28b
commit e3eb9612af
2 changed files with 46 additions and 1 deletions

View File

@ -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);

View File

@ -3,7 +3,7 @@
*
* Part of the PSXSDK C library
*/
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@ -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;