Patrick Georgi has submitted this change. ( https://review.coreboot.org/c/coreboot/+/41420 )
Change subject: lib: Add strtok() and strtok_r() ......................................................................
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 --- M src/include/string.h M src/lib/string.c 2 files changed, 27 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Werner Zeh: Looks good to me, approved
diff --git a/src/include/string.h b/src/include/string.h index f923ca5..8eef068 100644 --- a/src/include/string.h +++ b/src/include/string.h @@ -29,6 +29,8 @@ 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);
/** diff --git a/src/lib/string.c b/src/lib/string.c index f0c24ed..e8f72a2 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -163,6 +163,31 @@ 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;