diff --git a/src/xpdev/genwrap.c b/src/xpdev/genwrap.c index 1c8934b602ca0eb79a499ed41bc3923b42c0b837..3b258f22a08b32cf44217ed0ce05b1f7b85870f0 100644 --- a/src/xpdev/genwrap.c +++ b/src/xpdev/genwrap.c @@ -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 */ /****************************************************************************/ diff --git a/src/xpdev/genwrap.h b/src/xpdev/genwrap.h index 5b7cc7c812d6e1b281889db980bf89e6f89feebd..76d116c91799936b8ce5fd0f6cc8f4b05da35c89 100644 --- a/src/xpdev/genwrap.h +++ b/src/xpdev/genwrap.h @@ -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__)