Chromium Code Reviews| Index: runtime/bin/directory_openbsd.cc |
| diff --git a/runtime/bin/directory_macos.cc b/runtime/bin/directory_openbsd.cc |
| similarity index 96% |
| copy from runtime/bin/directory_macos.cc |
| copy to runtime/bin/directory_openbsd.cc |
| index 55994aa79abdd26998d52d5f3a4de0f706bd918a..3f293e2966ca171d6a7b10cd10a517d975ce8f37 100644 |
| --- a/runtime/bin/directory_macos.cc |
| +++ b/runtime/bin/directory_openbsd.cc |
| @@ -3,7 +3,7 @@ |
| // BSD-style license that can be found in the LICENSE file. |
| #include "platform/globals.h" |
| -#if defined(TARGET_OS_MACOS) |
| +#if defined(TARGET_OS_OPENBSD) |
| #include "bin/directory.h" |
| @@ -51,7 +51,7 @@ bool PathBuffer::Add(const char* name) { |
| data[PATH_MAX] = '\0'; |
| if (written <= PATH_MAX - length_ && |
| written >= 0 && |
| - static_cast<size_t>(written) == strlen(name)) { |
| + static_cast<size_t>(written) == strnlen(name, PATH_MAX + 1)) { |
| length_ += written; |
| return true; |
| } else { |
| @@ -343,7 +343,15 @@ Directory::ExistsResult Directory::Exists(const char* dir_name) { |
| char* Directory::Current() { |
| - return getcwd(NULL, 0); |
| + // Android's getcwd adheres closely to the POSIX standard. It won't |
|
ricow1
2016/01/05 07:12:13
Android's?
mulander
2016/01/05 16:13:48
You are correct. getcwd(3) on OpenBSD does allocat
mulander
2016/01/05 16:13:48
Acknowledged.
mulander
2016/01/05 16:13:48
Done.
|
| + // allocate memory. We need to make our own copy. |
| + |
| + char buffer[PATH_MAX]; |
| + if (NULL == getcwd(buffer, PATH_MAX)) { |
| + return NULL; |
| + } |
| + |
| + return strdup(buffer); |
| } |
| @@ -364,7 +372,6 @@ bool Directory::Create(const char* dir_name) { |
| return (result == 0); |
| } |
| - |
| char* Directory::SystemTemp() { |
| const char* temp_dir = getenv("TMPDIR"); |
| if (temp_dir == NULL) { |
| @@ -382,7 +389,6 @@ char* Directory::SystemTemp() { |
| return result; |
| } |
| - |
| char* Directory::CreateTemp(const char* prefix) { |
| // Returns a new, unused directory name, adding characters to the end |
| // of prefix. Creates the directory with the permissions specified |
| @@ -431,4 +437,4 @@ bool Directory::Rename(const char* path, const char* new_path) { |
| } // namespace bin |
| } // namespace dart |
| -#endif // defined(TARGET_OS_MACOS) |
| +#endif // defined(TARGET_OS_OPENBSD) |