Index: runtime/bin/directory_android.cc |
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_android.cc |
similarity index 96% |
copy from runtime/bin/directory_posix.cc |
copy to runtime/bin/directory_android.cc |
index 7adb80f9156ab2d308131aee2181243b35b85a27..29e2163b2d19b8fb032f13a6dc55b02bcb993f26 100644 |
--- a/runtime/bin/directory_posix.cc |
+++ b/runtime/bin/directory_android.cc |
@@ -376,7 +376,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 |
+ // allocate memory. We need to make our own copy. |
+ |
+ char buffer[PATH_MAX]; |
+ if (NULL == getcwd(buffer, PATH_MAX)) { |
+ return NULL; |
+ } |
+ |
+ return strdup(buffer); |
} |
@@ -387,6 +395,18 @@ bool Directory::Create(const char* dir_name) { |
} |
+// Android doesn't currently provide mkdtemp |
+static char* Mkdtemp(char* path_template) { |
+ if (mktemp(path_template) == NULL) { |
+ return NULL; |
+ } |
+ if (mkdir(path_template, 0700) != 0) { |
+ return NULL; |
+ } |
+ return path_template; |
+} |
+ |
+ |
char* Directory::CreateTemp(const char* const_template) { |
// Returns a new, unused directory name, modifying the contents of |
// dir_template. Creates the directory with the permissions specified |
@@ -406,7 +426,7 @@ char* Directory::CreateTemp(const char* const_template) { |
} |
char* result; |
do { |
- result = mkdtemp(path); |
+ result = Mkdtemp(path); |
} while (result == NULL && errno == EINTR); |
if (result == NULL) { |
free(path); |