Commit 7418f5e211cb73d0104791e1759effee9b9f2eb3

Luke Dashjr 2012-07-27T21:15:19

strtok_ts: Thread-safe strtok that work on POSIX or Windows

diff --git a/compat.h b/compat.h
index c6e38d8..19a14f0 100644
--- a/compat.h
+++ b/compat.h
@@ -9,6 +9,10 @@
 
 #include <windows.h>
 
+// NOTE: Windows strtok uses a thread-local static buffer, so this is safe
+#define SETUP_STRTOK_TS  /*nothing needed*/
+#define strtok_ts  strtok
+
 #include "miner.h"  // for timersub
 
 static inline int nanosleep(const struct timespec *req, struct timespec *rem)
@@ -72,8 +76,13 @@ typedef long suseconds_t;
 #endif
 
 #define PTH(thr) ((thr)->pth.p)
-#else
+#else /* ! WIN32 */
+
 #define PTH(thr) ((thr)->pth)
+
+#define SETUP_STRTOK_TS  char*_strtok_ts_saveptr
+#define strtok_ts(str, delim)  strtok_r(str, delim, &_strtok_ts_saveptr)
+
 #endif /* WIN32 */
 
 #endif /* __COMPAT_H__ */