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

Unified Diff: runtime/bin/directory_android.cc

Issue 10826233: Add _android files for building DartVM on Android (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporate reviewer's feedback (asiva, Soren Gjesse) Created 8 years, 4 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 | « runtime/bin/dbg_connection_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/directory_android.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_android.cc
similarity index 91%
copy from runtime/bin/directory_posix.cc
copy to runtime/bin/directory_android.cc
index 7adb80f9156ab2d308131aee2181243b35b85a27..dbdfca77744f937bae8e721d07fd4745a72ff988 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,19 @@ bool Directory::Create(const char* dir_name) {
}
+// Android doesn't currently provide mkdtemp. Once Android provied mkdtemp,
+// remove this function in favor of calling mkdtemp directly.
+static char* MakeTempDirectory(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 +423,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 = MakeTempDirectory(path);
} while (result == NULL && errno == EINTR);
if (result == NULL) {
free(path);
« no previous file with comments | « runtime/bin/dbg_connection_android.cc ('k') | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698