ref: e81cd3b1b198c9b23885be41293d091485a50e4e
parent: 32478e74e0c0c9303bf4c474bcb41bea674962c2
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Feb 21 05:09:20 EST 2017
[libc] Add strtok.c
--- a/libc/src/Makefile
+++ b/libc/src/Makefile
@@ -3,7 +3,7 @@
LIBCOBJ = assert.o strcpy.o strcmp.o strlen.o strchr.o \
strrchr.o strcat.o strncpy.o strncat.o strcoll.o \
- strxfrm.o \
+ strxfrm.o strtok.o \
memset.o memcpy.o memmove.o memcmp.o memchr.o \
isalnum.o isalpha.o isascii.o isblank.o iscntrl.o isdigit.o \
isgraph.o islower.o isprint.o ispunct.o isspace.o isupper.o \
--- /dev/null
+++ b/libc/src/strtok.c
@@ -1,0 +1,26 @@
+/* See LICENSE file for copyright and license details. */
+
+#include <string.h>
+
+char *
+strtok(const char *s, const char *delim)
+{
+ static char *line;
+
+ if (s)
+ line = s;
+ if (!s && !line)
+ return NULL;
+
+ s = line + strspn(line, delim);
+ if (*s == '\0')
+ return line = NULL;
+
+ line = s + strcspn(s, delim);
+ if (*line != '\0')
+ *line++ = '\0';
+ else
+ line = NULL;
+
+ return s;
+}