Commit 7a523e2f authored by ager@chromium.org's avatar ager@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1148 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 78de0cef
......@@ -195,7 +195,19 @@ char *OS::StrDup(const char* str) {
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;
}
......
......@@ -199,12 +199,14 @@ char* OS::StrNDup(const char* str, size_t n) {
// 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;
}
......
......@@ -704,12 +704,14 @@ char* OS::StrNDup(const char* str, size_t n) {
// 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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment