summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorharshit <harshitsharmajs@gmail.com>2020-05-15 10:40:02 +0530
committerPatrick Georgi <pgeorgi@google.com>2020-05-28 09:52:51 +0000
commit7a6f27ce1ed8ad535aaff13cc36af30b228556cc (patch)
tree776cec026f5ed3838354c2c0401f4093a47e005b /src/lib
parent58b8054ccacd0877bd52b640c7938f7582f6d69a (diff)
downloadcoreboot-7a6f27ce1ed8ad535aaff13cc36af30b228556cc.tar.xz
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>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/string.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/lib/string.c b/src/lib/string.c
index f0c24edcfc..e8f72a28e8 100644
--- a/src/lib/string.c
+++ b/src/lib/string.c
@@ -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;