Harshit Sharma has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/41420 )
Change subject: src/lib/string.c: Add strtok() and strtok_r() ......................................................................
src/lib/string.c: Add strtok() and strtok_r()
Add strtok() and strtok_r() to the library.
Signed-off-by: Harshit Sharma harshitsharmajs@gmail.com Change-Id: Ic855b31669be1c274cbf247c53ffa6f74ec5bf35 --- M src/include/string.h M src/lib/string.c 2 files changed, 24 insertions(+), 0 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/20/41420/1
diff --git a/src/include/string.h b/src/include/string.h index f923ca5..9356e3b 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -30,6 +30,8 @@ int strspn(const char *str, const char *spn); int strcspn(const char *str, const char *spn); long atol(const char *str); +char *strtok(char *str, const char *delim); +char *strtok_r(char *str, const char *delim, char **ptr);
/** * Find a character in a string. diff --git a/src/lib/string.c b/src/lib/string.c index f0c24ed..7bec606 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -5,6 +5,8 @@ #include <stddef.h> #include <stdlib.h>
+static char **strtok_global; + char *strdup(const char *s) { if (!ENV_RAMSTAGE) @@ -184,3 +186,23 @@ } return ret * sign; } + +char *strtok_r(char *str, const char *delim, char **ptr) +{ + if (str == NULL) + str = *ptr; + char *start = str + strspn(str, delim); + if (start[0] == '\0') + return NULL; + + char *end = start + strcspn(start, delim); + *ptr = end; + if (end[0] != '\0') + *(*ptr)++ = '\0'; + return start; +} + +char *strtok(char *str, const char *delim) +{ + return strtok_r(str, delim, strtok_global); +}