From 92d397d0bff2b22a0dbfe11dc3d1710950988133 Mon Sep 17 00:00:00 2001 From: jmcmullan Date: Sun, 13 Oct 2013 15:19:54 +0000 Subject: [PATCH] stdc.library: Add missing strtok_r.c Signed-off-by: Jason S. McMullan git-svn-id: https://svn.aros.org/svn/aros/trunk/AROS@48285 fb15a70f-31f2-0310-bbcc-cdcc74a49acc --- compiler/stdc/strtok_r.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 compiler/stdc/strtok_r.c diff --git a/compiler/stdc/strtok_r.c b/compiler/stdc/strtok_r.c new file mode 100644 index 0000000000..7fb185f416 --- /dev/null +++ b/compiler/stdc/strtok_r.c @@ -0,0 +1,88 @@ +/* + Copyright © 1995-2013, The AROS Development Team. All rights reserved. + $Id$ + + POSIX.1-2001 function strtok_r(). +*/ + +/***************************************************************************** + + NAME */ +#include + + char * strtok_r ( + +/* SYNOPSIS */ + char * str, + const char * sep, + char **saveptr) + +/* FUNCTION + Separates a string by the characters in sep. + + INPUTS + str - The string to check or NULL if the next word in + the last string is to be searched. + sep - Characters which separate "words" in str. + saveptr - internal context for next scan + + RESULT + The first word in str or the next one if str is NULL. + + NOTES + The function changes str ! + + EXAMPLE + char buffer[64]; + char *ptr; + + strcpy (buffer, "Hello, this is a test."); + + // Init. Returns "Hello" + strtok_r (str, " \t,.", &ptr); + + // Next word. Returns "this" + strtok_r (NULL, " \t,.", &ptr); + + // Next word. Returns "is" + strtok_r (NULL, " \t", &ptr); + + // Next word. Returns "a" + strtok_r (NULL, " \t", &ptr); + + // Next word. Returns "test." + strtok_r (NULL, " \t", &ptr); + + // Next word. Returns NULL. + strtok_r (NULL, " \t", &ptr); + + BUGS + + SEE ALSO + + INTERNALS + +******************************************************************************/ +{ + char * t = *saveptr; + + if (str != NULL) + t = str; + else + str = t; + + str += strspn (str, sep); + + if (*str == '\0') + return NULL; + + t = str; + + t += strcspn (str, sep); + + if (*t != '\0') + *t ++ = '\0'; + + *saveptr = t; + return str; +} /* strtok_r */ -- 2.11.4.GIT