Skip to content

Commit 671bdfc

Browse files
committed
Add strtok_r stub for MinGW
1 parent 536af3a commit 671bdfc

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/tools/geoip.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,39 @@
2727

2828
#ifdef __MINGW32__
2929
# include <Winsock.h>
30+
/*
31+
* public domain strtok_r() by Charlie Gordon
32+
*
33+
* from comp.lang.c 9/14/2007
34+
*
35+
* http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684
36+
*
37+
* (Declaration that it's public domain):
38+
* http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c
39+
*/
40+
41+
char* strtok_r(char *str, const char *delim, char **nextp)
42+
{
43+
char *ret;
44+
45+
if (str == NULL)
46+
str = *nextp;
47+
48+
str += strspn(str, delim);
49+
50+
if (*str == '\0')
51+
return NULL;
52+
53+
ret = str;
54+
str += strcspn(str, delim);
55+
56+
if (*str)
57+
*str++ = '\0';
58+
59+
*nextp = str;
60+
61+
return ret;
62+
}
3063
#else
3164
# include <sys/socket.h>
3265
# include <netinet/in.h>

0 commit comments

Comments
 (0)