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..4b1621907b14d32ff3d8c2ef6c28e3b666e87ed6 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* _template) { |
cshapiro
2012/08/07 22:39:40
Sorry I missed the first time but _template should
jackpal
2012/08/08 00:26:19
Done.
|
+ if (mktemp(_template) == NULL) { |
+ return NULL; |
+ } |
+ if (mkdir(_template, 0700) != 0) { |
+ return NULL; |
+ } |
+ return _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); |