From: Marco Schlumpp Date: Tue, 29 Mar 2022 12:23:52 +0000 (+0200) Subject: lib/nolibc: Implement strsep function X-Git-Tag: RELEASE-0.13.0~81 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=eac4a8dc00c62398eb6eaf54b6eb5f9440bc2230;p=unikraft%2Funikraft.git lib/nolibc: Implement strsep function This function is an improvement of strtok that originates from BSD. Signed-off-by: Marco Schlumpp Reviewed-by: Razvan Deaconescu Reviewed-by: Marc Rittinghaus Approved-by: Marc Rittinghaus Tested-by: Unikraft CI GitHub-Closes: #627 --- diff --git a/lib/nolibc/exportsyms.uk b/lib/nolibc/exportsyms.uk index e169d1d02..a283695fb 100644 --- a/lib/nolibc/exportsyms.uk +++ b/lib/nolibc/exportsyms.uk @@ -77,6 +77,7 @@ strcspn strspn strtok strtok_r +strsep strndup strdup strlcpy diff --git a/lib/nolibc/include/string.h b/lib/nolibc/include/string.h index 0fda98db7..ae52ab8e8 100644 --- a/lib/nolibc/include/string.h +++ b/lib/nolibc/include/string.h @@ -64,6 +64,7 @@ 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 *strsep(char **restrict s, const char *restrict sep); char *strndup(const char *str, size_t len); char *strdup(const char *str); char *strcat(char *restrict dest, const char *restrict src); diff --git a/lib/nolibc/string.c b/lib/nolibc/string.c index d88853304..eacfbe8c7 100644 --- a/lib/nolibc/string.c +++ b/lib/nolibc/string.c @@ -299,6 +299,23 @@ char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p) return s; } +char *strsep(char **restrict s, const char *restrict sep) +{ + char *p, *str = *s; + + if (!*s) + return NULL; + + p = *s + strcspn(*s, sep); + if (*p) + *p++ = 0; + else + p = NULL; + + *s = p; + return str; +} + char *strndup(const char *str, size_t len) { char *__res;