Merge revision 21321 to trunk. Fixes issue 8930
- Add strndup for Mac OS X version < 10.7.
Review URL: https://codereview.chromium.org//13873008
git-svn-id: http://dart.googlecode.com/svn/trunk@21340 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/runtime/platform/c99_support_win.h b/runtime/platform/c99_support_win.h
index 0c06add..2859f0c 100644
--- a/runtime/platform/c99_support_win.h
+++ b/runtime/platform/c99_support_win.h
@@ -65,18 +65,4 @@
}
}
-// size_t used to match function signature on other platforms.
-static inline char* strndup(const char* s, size_t n) {
- size_t len = strlen(s);
- if (n < len) {
- len = n;
- }
- char* result = reinterpret_cast<char*>(malloc(len + 1));
- if (!result) {
- return NULL;
- }
- result[len] = '\0';
- return reinterpret_cast<char*>(memcpy(result, s, len));
-}
-
#endif // PLATFORM_C99_SUPPORT_WIN_H_
diff --git a/runtime/platform/globals.h b/runtime/platform/globals.h
index 2d566bb..ef56ad4 100644
--- a/runtime/platform/globals.h
+++ b/runtime/platform/globals.h
@@ -396,6 +396,36 @@
}
+// Some platforms do not support strndup. We add it below as necessary.
+#if defined(TARGET_OS_MACOS)
+// strndup has only been added to Mac OS X in 10.7. We are supplying
+// our own copy here.
+#if !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__) || \
+ __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ <= 1060
+#define NEEDS_STRNDUP 1
+#endif // !defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
+#elif defined(TARGET_OS_WINDOWS)
+#define NEEDS_STRNDUP 1
+#endif // defined(TARGET_OS_MACOS)
+
+#if defined(NEEDS_STRNDUP)
+// size_t used to match function signature on other platforms.
+inline char* strndup(const char* s, size_t n) {
+ size_t len = strlen(s);
+ if (n < len) {
+ len = n;
+ }
+ char* result = reinterpret_cast<char*>(malloc(len + 1));
+ if (!result) {
+ return NULL;
+ }
+ result[len] = '\0';
+ return reinterpret_cast<char*>(memcpy(result, s, len));
+}
+#endif // defined(NEEDS_STRNDUP)
+#undef NEEDS_STRNDUP
+
+
// A macro to ensure that memcpy cannot be called. memcpy does not handle
// overlapping memory regions. Even though this is well documented it seems
// to be used in error quite often. To avoid problems we disallow the direct
diff --git a/tools/VERSION b/tools/VERSION
index 923de50..fe64738 100644
--- a/tools/VERSION
+++ b/tools/VERSION
@@ -1,4 +1,4 @@
MAJOR 0
MINOR 4
BUILD 5
-PATCH 1
+PATCH 2