| Index: runtime/bin/directory_android.cc
|
| diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_android.cc
|
| similarity index 92%
|
| copy from runtime/bin/directory_posix.cc
|
| copy to runtime/bin/directory_android.cc
|
| index 7adb80f9156ab2d308131aee2181243b35b85a27..2bad45620e8f2ffa012c6711a0db599de47ebd5f 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
|
| @@ -402,11 +422,22 @@ char* Directory::CreateTemp(const char* const_template) {
|
| snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX");
|
| }
|
| } else {
|
| - snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX");
|
| + // Android does not have a /tmp directory. A partial substitute,
|
| + // suitable for bring-up work and tests, is to create a tmp
|
| + // directory in /data/local/tmp.
|
| + //
|
| + // TODO(4413): In the long run, when running in an application we should
|
| + // probably use android.content.Context.getCacheDir().
|
| + #define ANDROID_TEMP_DIR "/data/local/tmp"
|
| + struct stat st;
|
| + if (stat(ANDROID_TEMP_DIR, &st) != 0) {
|
| + mkdir(ANDROID_TEMP_DIR, 0777);
|
| + }
|
| + snprintf(path, PATH_MAX, ANDROID_TEMP_DIR "/temp_dir1_XXXXXX");
|
| }
|
| char* result;
|
| do {
|
| - result = mkdtemp(path);
|
| + result = Mkdtemp(path);
|
| } while (result == NULL && errno == EINTR);
|
| if (result == NULL) {
|
| free(path);
|
|
|