Merge pull request #442 from kwolekr/mingw_compile_fix
authorkwolekr <mirrorisim@gmail.com>
Tue, 29 Jan 2013 21:07:47 +0000 (13:07 -0800)
committerkwolekr <mirrorisim@gmail.com>
Tue, 29 Jan 2013 21:07:47 +0000 (13:07 -0800)
Fix compile under MingW

src/porting.h
src/util/string.cpp
src/util/string.h

index 184e1ab54e1ab393f317ea48154e2611cc3f3a74..c8d19154c9c341fde8b708d4939e7c8e71f82233 100644 (file)
@@ -42,18 +42,26 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #ifdef _WIN32
        #include <windows.h>
        
-       #define ALIGNOF(x) __alignof(x)
        #define sleep_ms(x) Sleep(x)
+#else
+       #include <unistd.h>
+       #include <stdint.h> //for uintptr_t
+       
+       #define sleep_ms(x) usleep(x*1000)
+#endif
+
+#ifdef _MSC_VER
+       #define ALIGNOF(x) __alignof(x)
        #define strtok_r(x, y, z) strtok_s(x, y, z)
        #define strtof(x, y) (float)strtod(x, y)
        #define strtoll(x, y, z) _strtoi64(x, y, z)
        #define strtoull(x, y, z) _strtoui64(x, y, z)
 #else
-       #include <unistd.h>
-       #include <stdint.h> //for uintptr_t
-       
        #define ALIGNOF(x) __alignof__(x)
-       #define sleep_ms(x) usleep(x*1000)
+#endif
+
+#ifdef __MINGW32__
+       #define strtok_r(x, y, z) mystrtok_r(x, y, z)
 #endif
 
 #define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))
index 215ac299d13cab211219cda3bfc55c1b772a58ca..c10755ae1dba68d47c314ab9821ead0d06bbb54b 100644 (file)
@@ -47,3 +47,28 @@ size_t curl_write_data(char *ptr, size_t size, size_t nmemb, void *userdata) {
     stream->write(ptr, count);
     return count;
 }
+
+char *mystrtok_r(char *s, const char *sep, char **lasts) {
+       char *t;
+
+       if (!s)
+               s = *lasts;
+
+       while (*s && strchr(sep, *s))
+               s++;
+
+       if (!*s)
+               return NULL;
+
+       t = s;
+       while (*t) {
+               if (strchr(sep, *t)) {
+                       *t++ = '\0';
+                       break;
+               }
+               t++;
+       }
+       
+       *lasts = t;
+       return s;
+}
index 58274c6773cd7a3807c52c7df7674e29734a81fc..d081b365b42fd837846dedfaa84208c28d32a6a5 100644 (file)
@@ -283,6 +283,7 @@ inline std::string wrap_rows(const std::string &from, u32 rowlen)
 
 std::string translatePassword(std::string playername, std::wstring password);
 size_t curl_write_data(char *ptr, size_t size, size_t nmemb, void *userdata);
+char *mystrtok_r(char *s, const char *sep, char **lasts);
 
 #endif