[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/nolibc: Introduce strtok_r



The code taken from musl.
File: src/string/strtok_r.c
Commit Id: 400c5e5c8307

Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx>
---
 lib/nolibc/exportsyms.uk    |  1 +
 lib/nolibc/include/string.h |  1 +
 lib/nolibc/string.c         | 15 +++++++++++++++
 3 files changed, 17 insertions(+)

diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk
index c542f3a..cf083ef 100644
--- a/lib/nolibc/exportsyms.uk
+++ b/lib/nolibc/exportsyms.uk
@@ -65,6 +65,7 @@ strcmp
 strcspn
 strspn
 strtok
+strtok_r
 strndup
 strdup
 strlcpy
diff --git a/lib/nolibc/include/string.h b/lib/nolibc/include/string.h
index c5f0caa..9a1a63c 100644
--- a/lib/nolibc/include/string.h
+++ b/lib/nolibc/include/string.h
@@ -65,6 +65,7 @@ int strcmp(const char *str1, const char *str2);
 size_t strcspn(const char *s, const char *c);
 size_t strspn(const char *s, const char *c);
 char *strtok(char *restrict s, const char *restrict sep);
+char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p);
 char *strndup(const char *str, size_t len);
 char *strdup(const char *str);
 
diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c
index d4d1db2..327efcc 100644
--- a/lib/nolibc/string.c
+++ b/lib/nolibc/string.c
@@ -285,6 +285,21 @@ char *strtok(char *restrict s, const char *restrict sep)
        return s;
 }
 
+char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p)
+{
+       if (!s && !(s = *p))
+               return NULL;
+       s += strspn(s, sep);
+       if (!*s)
+               return *p = 0;
+       *p = s + strcspn(s, sep);
+       if (**p)
+               *(*p)++ = 0;
+       else
+               *p = 0;
+       return s;
+}
+
 char *strndup(const char *str, size_t len)
 {
        char *__res;
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.