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
This commit is contained in:
parent
78de0cef11
commit
7a523e2f92
@ -195,7 +195,19 @@ char *OS::StrDup(const char* str) {
|
|||||||
|
|
||||||
|
|
||||||
char* OS::StrNDup(const char* str, size_t n) {
|
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
|
// Stupid implementation of strndup since macos isn't born with
|
||||||
// one.
|
// one.
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
if (len <= n)
|
if (len <= n) {
|
||||||
return StrDup(str);
|
return StrDup(str);
|
||||||
|
}
|
||||||
char* result = new char[n+1];
|
char* result = new char[n+1];
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i <= n; i++)
|
for (i = 0; i <= n; i++) {
|
||||||
result[i] = str[i];
|
result[i] = str[i];
|
||||||
|
}
|
||||||
result[i] = '\0';
|
result[i] = '\0';
|
||||||
return result;
|
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
|
// Stupid implementation of strndup since windows isn't born with
|
||||||
// one.
|
// one.
|
||||||
size_t len = strlen(str);
|
size_t len = strlen(str);
|
||||||
if (len <= n)
|
if (len <= n) {
|
||||||
return StrDup(str);
|
return StrDup(str);
|
||||||
|
}
|
||||||
char* result = new char[n+1];
|
char* result = new char[n+1];
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0; i <= n; i++)
|
for (i = 0; i <= n; i++) {
|
||||||
result[i] = str[i];
|
result[i] = str[i];
|
||||||
|
}
|
||||||
result[i] = '\0';
|
result[i] = '\0';
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user