---
 compat/compat_strlib.c             | 40 ++++++++++++++++++++++++++++++++++++++
 converter/babeltrace.c             |  2 +-
 include/babeltrace/compat/string.h |  4 ++++
 3 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/compat/compat_strlib.c b/compat/compat_strlib.c
index 7413e74..3cbd455 100644
--- a/compat/compat_strlib.c
+++ b/compat/compat_strlib.c
@@ -1,6 +1,46 @@
 #include <babeltrace/compat/string.h>
 
 #ifdef __MINGW32__
+
+char* strtok_r(
+       char *str,
+       const char *delim,
+       char **nextp)
+{
+       char *ret;
+
+       /* if str is NULL, continue from nextp */
+       if (str == NULL) {
+               str = *nextp;
+       }
+       /* skip the leading delimiter characters */
+       str += strspn(str, delim);
+
+       /* return NULL if all are delimiters */
+       if (*str == '\0') {
+               return NULL;
+       }
+       /* return the pointer to the first character that is not delimiter */
+       ret = str;
+
+       /* scan to the next delimiter */
+       str += strcspn(str, delim);
+
+       /* if we found a delimiter instead of a NUL */
+       if (*str) {
+               /* replace the delimiter with the NUL */
+               *str = '\0';
+               /* next time, scan from the character after NUL */
+               *nextp = str + 1;
+       }
+       else {
+               /* end of string: next time, scan at the end (NUL) again */
+               *nextp = str;
+       }
+
+       return ret;
+}
+
 int strerror_r(int errnum, char *buf, size_t buflen)
 {
        /* non-recursive implementation of strerror_r */
diff --git a/converter/babeltrace.c b/converter/babeltrace.c
index 7b3db49..f4a9217 100644
--- a/converter/babeltrace.c
+++ b/converter/babeltrace.c
@@ -49,7 +49,7 @@
 #include <unistd.h>
 #include <inttypes.h>
 #include <babeltrace/compat/ftw.h>
-#include <string.h>
+#include <babeltrace/compat/string.h>
 
 #include <babeltrace/ctf-ir/metadata.h>        /* for clocks */
 
diff --git a/include/babeltrace/compat/string.h 
b/include/babeltrace/compat/string.h
index 8591b7e..501d003 100644
--- a/include/babeltrace/compat/string.h
+++ b/include/babeltrace/compat/string.h
@@ -3,6 +3,10 @@
 
 #include <string.h>
 
+#ifdef __MINGW32__
+char *strtok_r(char *str, const char *delim, char **nextp);
+#endif
+
 int compat_strerror_r(int errnum, char *buf, size_t buflen);
 
 #endif
-- 
1.8.1.msysgit.1


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to