(svn r14154) -Fix (r14153): strndup is a GNU extension, so it doesn't exist on all platforms
authorglx
Sun, 24 Aug 2008 17:02:21 +0000
changeset 9997 d858e88e871a
parent 9996 fceaf224b2f0
child 9998 2bf26d44bc33
(svn r14154) -Fix (r14153): strndup is a GNU extension, so it doesn't exist on all platforms
src/stdafx.h
src/string.cpp
src/string_func.h
--- a/src/stdafx.h	Sun Aug 24 13:50:31 2008 +0000
+++ b/src/stdafx.h	Sun Aug 24 17:02:21 2008 +0000
@@ -145,6 +145,11 @@
 	#include <malloc.h> // alloca()
 #endif
 
+#if defined(__MINGW32__) && defined(_GNU_SOURCE)
+	/* For some weird reasons, SDL defines _GNU_SOURCE */
+	#undef _GNU_SOURCE
+#endif
+
 #if defined(WIN32)
 	#define WIN32_LEAN_AND_MEAN     // Exclude rarely-used stuff from Windows headers
 #endif
--- a/src/string.cpp	Sun Aug 24 13:50:31 2008 +0000
+++ b/src/string.cpp	Sun Aug 24 17:02:21 2008 +0000
@@ -304,3 +304,14 @@
 	*s = '\0';
 	return length;
 }
+
+#ifndef _GNU_SOURCE
+#include "core/math_func.hpp"
+char *strndup(const char *s, size_t len)
+{
+	len = min(strlen(s), len);
+	char *tmp = CallocT<char>(len + 1);
+	memcpy(tmp, s, len);
+	return tmp;
+}
+#endif /* !_GNU_SOURCE */
--- a/src/string_func.h	Sun Aug 24 13:50:31 2008 +0000
+++ b/src/string_func.h	Sun Aug 24 17:02:21 2008 +0000
@@ -156,4 +156,9 @@
 	;
 }
 
-#endif /* STRING_FUNC_H */
+#ifndef _GNU_SOURCE
+/* strndup is a GNU extension */
+char *strndup(const char *s, size_t len);
+#endif /* WIN32 || SUNOS */
+
+#endif /* !_GNU_SOURCE */