scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 0bb819c2423f68687ac0a6376ce6f1a6967a5a51
parent c8f1b2b548d1ca0f577e3005ce3514cddd6f491f
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Tue, 21 Feb 2017 10:09:20 +0100

[libc] Add strtok.c

Diffstat:
libc/src/Makefile | 2+-
libc/src/strtok.c | 26++++++++++++++++++++++++++
2 files changed, 27 insertions(+), 1 deletion(-)

diff --git 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 @@ -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; +}