util: added strtok_r implementation for old compilers
Visual studios older than 2005 don't have strtok_s() and according to MSDN vs2005 has NOT thread-safe strtok().
This commit is contained in:
22
src/util.c
22
src/util.c
@@ -55,6 +55,28 @@ char *xmpp_strdup(const xmpp_ctx_t * const ctx, const char * const s)
|
||||
return copy;
|
||||
}
|
||||
|
||||
/** strtok_r(3) implementation.
|
||||
* This function has appeared in POSIX.1-2001, but not in C standard.
|
||||
* For example, visual studio older than 2005 doesn't provide strtok_r()
|
||||
* nor strtok_s().
|
||||
*/
|
||||
char *xmpp_strtok_r(char *s, const char *delim, char **saveptr)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
s = s ? s : *saveptr;
|
||||
len = strspn(s, delim);
|
||||
s += len;
|
||||
if (*s == '\0')
|
||||
return NULL;
|
||||
|
||||
len = strcspn(s, delim);
|
||||
*saveptr = s[len] == '\0' ? &s[len] : &s[len + 1];
|
||||
s[len] = '\0';
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
/** Return an integer based time stamp.
|
||||
* This function uses gettimeofday or timeGetTime (on Win32 platforms) to
|
||||
* compute an integer based time stamp. This is used internally by the
|
||||
|
||||
Reference in New Issue
Block a user