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:
13
src/sasl.c
13
src/sasl.c
@@ -24,10 +24,17 @@
|
||||
#include "sha1.h"
|
||||
#include "scram.h"
|
||||
#include "rand.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#define strtok_r strtok_s
|
||||
#endif
|
||||
/* strtok_s() has appeared in visual studio 2005.
|
||||
Use own implementation for older versions. */
|
||||
#ifdef _MSC_VER
|
||||
# if (_MSC_VER >= 1400)
|
||||
# define strtok_r strtok_s
|
||||
# else
|
||||
# define strtok_r xmpp_strtok_r
|
||||
# endif
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
|
||||
/** generate authentication string for the SASL PLAIN mechanism */
|
||||
|
||||
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
|
||||
|
||||
@@ -18,6 +18,9 @@
|
||||
|
||||
#include "ostypes.h"
|
||||
|
||||
/* string functions */
|
||||
char *xmpp_strtok_r(char *s, const char *delim, char **saveptr);
|
||||
|
||||
/* timing functions */
|
||||
uint64_t time_stamp(void);
|
||||
uint64_t time_elapsed(uint64_t t1, uint64_t t2);
|
||||
|
||||
Reference in New Issue
Block a user