lib: Add strtok() and strtok_r()

Add strtok() and strtok_r() to the library.

Signed-off-by: Harshit Sharma <harshitsharmajs@gmail.com>
Change-Id: Ic855b31669be1c274cbf247c53ffa6f74ec5bf35
Reviewed-on: https://review.coreboot.org/c/coreboot/+/41420
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Werner Zeh <werner.zeh@siemens.com>
This commit is contained in:
harshit 2020-05-15 10:40:02 +05:30 committed by Patrick Georgi
parent 58b8054cca
commit 7a6f27ce1e
2 changed files with 27 additions and 0 deletions

View File

@ -29,6 +29,8 @@ int strcmp(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, int maxlen);
int strspn(const char *str, const char *spn);
int strcspn(const char *str, const char *spn);
char *strtok_r(char *str, const char *delim, char **ptr);
char *strtok(char *str, const char *delim);
long atol(const char *str);
/**

View File

@ -163,6 +163,31 @@ int strcspn(const char *str, const char *spn)
return ret;
}
char *strtok_r(char *str, const char *delim, char **ptr)
{
char *start;
char *end;
if (str == NULL)
str = *ptr;
start = str + strspn(str, delim);
if (start[0] == '\0')
return NULL;
end = start + strcspn(start, delim);
*ptr = end;
if (end[0] != '\0')
*(*ptr)++ = '\0';
return start;
}
char *strtok(char *str, const char *delim)
{
static char *strtok_ptr;
return strtok_r(str, delim, &strtok_ptr);
}
long atol(const char *str)
{
long ret = 0;