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

Unified Diff: runtime/bin/directory_android.cc

Issue 10823209: Add support for building the Dart VM for Android OS. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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
Index: runtime/bin/directory_android.cc
diff --git a/runtime/bin/directory_posix.cc b/runtime/bin/directory_android.cc
similarity index 93%
copy from runtime/bin/directory_posix.cc
copy to runtime/bin/directory_android.cc
index 7adb80f9156ab2d308131aee2181243b35b85a27..aad6aed0acf988dc701c3a4113812f4fc0cf40be 100644
--- a/runtime/bin/directory_posix.cc
+++ b/runtime/bin/directory_android.cc
@@ -376,7 +376,23 @@ 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;
+ }
+
+ size_t length = strlen(buffer);
cshapiro 2012/08/07 20:56:54 Instead of all of this code, would a single call t
jackpal 2012/08/07 21:43:26 Done.
+ char* result = reinterpret_cast<char*>(malloc(length + 1));
+ if (result == NULL) {
+ return NULL;
+ }
+
+ strncpy(result, buffer, length);
+ result[length] = '\0';
+ return result;
}
@@ -386,6 +402,21 @@ bool Directory::Create(const char* dir_name) {
return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0);
}
+// Android doesn't currenpty provide mkdtemp
+
cshapiro 2012/08/07 20:56:54 No need for an empty line here.
jackpal 2012/08/07 21:43:26 Done.
+static char* android_mkdtemp(char* _template) {
cshapiro 2012/08/07 20:56:54 This should be named Mkdtemp or something else tha
jackpal 2012/08/07 21:43:26 Done.
+ printf("mkdtemp %s\n", _template);
+ if (mktemp(_template) == NULL) {
+ printf("mktemp failed\n");
+ return NULL;
+ }
+ if (mkdir(_template, 0700) != 0) {
+ printf("mkdir failed\n");
+ return NULL;
+ }
+ printf("Success\n");
+ return _template;
+}
char* Directory::CreateTemp(const char* const_template) {
// Returns a new, unused directory name, modifying the contents of
@@ -406,7 +437,7 @@ char* Directory::CreateTemp(const char* const_template) {
}
char* result;
do {
- result = mkdtemp(path);
+ result = android_mkdtemp(path);
cshapiro 2012/08/07 20:56:54 ditto
jackpal 2012/08/07 21:43:26 Done.
} while (result == NULL && errno == EINTR);
if (result == NULL) {
free(path);
@@ -415,7 +446,6 @@ char* Directory::CreateTemp(const char* const_template) {
return path;
}
cshapiro 2012/08/07 20:56:54 Definitions are separated by 2 spaces. You should
jackpal 2012/08/07 21:43:26 Done.
-
bool Directory::Delete(const char* dir_name, bool recursive) {
if (!recursive) {
return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0);

Powered by Google App Engine
This is Rietveld 408576698