Skip to content
Snippets Groups Projects
Commit e32a3ea3 authored by rswindell's avatar rswindell
Browse files

Added a POSIX-compliant strtok_r() implementation for non-*nix platforms.

parent bcc386c6
Branches
Tags
No related merge requests found
......@@ -8,7 +8,7 @@
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright 2006 Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Lesser General Public License *
......@@ -231,6 +231,45 @@ char* strrev(char* str)
}
#endif
#if !defined(__unix__)
/****************************************************************************/
/* Implementations of the recursive (thread-safe) version of strtok */
/* Thanks to Apache Portable Runtime (APR) */
/****************************************************************************/
char* DLLCALL strtok_r(char *str, const char *delim, char **last)
{
char* token;
if (str==NULL) /* subsequent call */
str = *last; /* start where we left off */
/* skip characters in delimiter (will terminate at '\0') */
while(*str && strchr(delim, *str))
++str;
if(!*str) /* no more tokens */
return NULL;
token = str;
/* skip valid token characters to terminate token and
* prepare for the next call (will terminate at '\0)
*/
*last = token + 1;
while(**last && !strchr(delim, **last))
++*last;
if (**last) {
**last = '\0';
++*last;
}
return token;
}
#endif
/****************************************************************************/
/* Initialize (seed) the random number generator */
/****************************************************************************/
......
......@@ -290,6 +290,8 @@ DLLEXPORT int DLLCALL get_errno(void);
DLLEXPORT struct tm* DLLCALL localtime_r(const time_t* t, struct tm* tm);
DLLEXPORT char* DLLCALL ctime_r(const time_t *t, char *buf);
DLLEXPORT char* DLLCALL asctime_r(const struct tm *tm, char *buf);
DLLEXPORT char* DLLCALL strtok_r(char *str, const char *delim, char **last);
#endif
#if defined(__solaris__)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment