commit 0bb819c2423f68687ac0a6376ce6f1a6967a5a51
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Tue Feb 21 10:09:20 2017 +0100
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Tue Feb 21 10:09:20 2017 +0100

    [libc] Add strtok.c

diff --git a/libc/src/Makefile b/libc/src/Makefile
index f591fb3..47225a2 100644
--- 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 \
diff --git a/libc/src/strtok.c b/libc/src/strtok.c
new file mode 100644
index 0000000..33c99d1
--- /dev/null
+++ b/libc/src/strtok.c
@@ -0,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;
+}

Reply via email to