Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: runtime/bin/directory_posix.cc

Issue 10824159: Make Directory::Current() work with unenhanced POSIX getcwd (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_posix.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_posix.cc
index 7adb80f9156ab2d308131aee2181243b35b85a27..bcbae793eb2333b2791a6d20c76c3a0b3ce7e279 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_posix.cc
@@ -376,7 +376,33 @@ Directory::ExistsResult Directory::Exists(const char* dir_name) {
char* Directory::Current() {
+#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOS)
+
+ // On targets that support it, let getcwd allocate the buffer
+ // dynamically. (Not part of POSIX, but implemented on many platforms.)
+
return getcwd(NULL, 0);
+
+#else
+
+ // POSIX getcwd requires a pre-allocated buffer.
+
+ char buffer[PATH_MAX];
+ if (NULL == getcwd(buffer, PATH_MAX)) {
+ return NULL;
+ }
+
+ size_t length = strlen(buffer) + 1;
+ char* result = reinterpret_cast<char*>(malloc(length));
+ if (result == NULL) {
+ return NULL;
+ }
+
+ strncpy(result, buffer, length);
+ return result;
+
+#else
+#endif
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698