This function is an improvement of strtok that originates from BSD.
Signed-off-by: Marco Schlumpp <marco@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Approved-by: Marc Rittinghaus <marc.rittinghaus@unikraft.io>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Closes: #627
strspn
strtok
strtok_r
+strsep
strndup
strdup
strlcpy
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);
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;