Author: [email protected]
Date: Mon Jan 26 03:28:51 2009
New Revision: 1148
Modified:
branches/bleeding_edge/src/platform-freebsd.cc
branches/bleeding_edge/src/platform-macos.cc
branches/bleeding_edge/src/platform-win32.cc
Log:
Handle strndup in freebsd in the same way it is handled on other
platforms that do not support it directly.
Review URL: http://codereview.chromium.org/18585
Modified: branches/bleeding_edge/src/platform-freebsd.cc
==============================================================================
--- branches/bleeding_edge/src/platform-freebsd.cc (original)
+++ branches/bleeding_edge/src/platform-freebsd.cc Mon Jan 26 03:28:51 2009
@@ -195,7 +195,19 @@
char* OS::StrNDup(const char* str, size_t n) {
- return strndup(str, n);
+ // Stupid implementation of strndup since freebsd isn't born with
+ // one.
+ size_t len = strlen(str);
+ if (len <= n) {
+ return StrDup(str);
+ }
+ char* result = new char[n+1];
+ size_t i;
+ for (i = 0; i <= n; i++) {
+ result[i] = str[i];
+ }
+ result[i] = '\0';
+ return result;
}
Modified: branches/bleeding_edge/src/platform-macos.cc
==============================================================================
--- branches/bleeding_edge/src/platform-macos.cc (original)
+++ branches/bleeding_edge/src/platform-macos.cc Mon Jan 26 03:28:51 2009
@@ -199,12 +199,14 @@
// Stupid implementation of strndup since macos isn't born with
// one.
size_t len = strlen(str);
- if (len <= n)
+ if (len <= n) {
return StrDup(str);
+ }
char* result = new char[n+1];
size_t i;
- for (i = 0; i <= n; i++)
+ for (i = 0; i <= n; i++) {
result[i] = str[i];
+ }
result[i] = '\0';
return result;
}
Modified: branches/bleeding_edge/src/platform-win32.cc
==============================================================================
--- branches/bleeding_edge/src/platform-win32.cc (original)
+++ branches/bleeding_edge/src/platform-win32.cc Mon Jan 26 03:28:51 2009
@@ -704,12 +704,14 @@
// Stupid implementation of strndup since windows isn't born with
// one.
size_t len = strlen(str);
- if (len <= n)
+ if (len <= n) {
return StrDup(str);
+ }
char* result = new char[n+1];
size_t i;
- for (i = 0; i <= n; i++)
+ for (i = 0; i <= n; i++) {
result[i] = str[i];
+ }
result[i] = '\0';
return result;
}
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---