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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "bin/directory.h" 5 #include "bin/directory.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <sys/param.h> 9 #include <sys/param.h>
10 #include <sys/stat.h> 10 #include <sys/stat.h>
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 ASSERT(errno == ELOOP || 369 ASSERT(errno == ELOOP ||
370 errno == ENAMETOOLONG || 370 errno == ENAMETOOLONG ||
371 errno == ENOENT || 371 errno == ENOENT ||
372 errno == ENOTDIR); 372 errno == ENOTDIR);
373 return DOES_NOT_EXIST; 373 return DOES_NOT_EXIST;
374 } 374 }
375 } 375 }
376 376
377 377
378 char* Directory::Current() { 378 char* Directory::Current() {
379 return getcwd(NULL, 0); 379 // Android's getcwd adheres closely to the POSIX standard. It won't
380 // allocate memory. We need to make our own copy.
381
382 char buffer[PATH_MAX];
383 if (NULL == getcwd(buffer, PATH_MAX)) {
384 return NULL;
385 }
386
387 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.
388 char* result = reinterpret_cast<char*>(malloc(length + 1));
389 if (result == NULL) {
390 return NULL;
391 }
392
393 strncpy(result, buffer, length);
394 result[length] = '\0';
395 return result;
380 } 396 }
381 397
382 398
383 bool Directory::Create(const char* dir_name) { 399 bool Directory::Create(const char* dir_name) {
384 // Create the directory with the permissions specified by the 400 // Create the directory with the permissions specified by the
385 // process umask. 401 // process umask.
386 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); 402 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0);
387 } 403 }
388 404
405 // Android doesn't currenpty provide mkdtemp
406
cshapiro 2012/08/07 20:56:54 No need for an empty line here.
jackpal 2012/08/07 21:43:26 Done.
407 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.
408 printf("mkdtemp %s\n", _template);
409 if (mktemp(_template) == NULL) {
410 printf("mktemp failed\n");
411 return NULL;
412 }
413 if (mkdir(_template, 0700) != 0) {
414 printf("mkdir failed\n");
415 return NULL;
416 }
417 printf("Success\n");
418 return _template;
419 }
389 420
390 char* Directory::CreateTemp(const char* const_template) { 421 char* Directory::CreateTemp(const char* const_template) {
391 // Returns a new, unused directory name, modifying the contents of 422 // Returns a new, unused directory name, modifying the contents of
392 // dir_template. Creates the directory with the permissions specified 423 // dir_template. Creates the directory with the permissions specified
393 // by the process umask. 424 // by the process umask.
394 // The return value must be freed by the caller. 425 // The return value must be freed by the caller.
395 char* path = static_cast<char*>(malloc(PATH_MAX + 1)); 426 char* path = static_cast<char*>(malloc(PATH_MAX + 1));
396 SafeStrNCpy(path, const_template, PATH_MAX + 1); 427 SafeStrNCpy(path, const_template, PATH_MAX + 1);
397 int path_length = strlen(path); 428 int path_length = strlen(path);
398 if (path_length > 0) { 429 if (path_length > 0) {
399 if ((path)[path_length - 1] == '/') { 430 if ((path)[path_length - 1] == '/') {
400 snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX"); 431 snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX");
401 } else { 432 } else {
402 snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX"); 433 snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX");
403 } 434 }
404 } else { 435 } else {
405 snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX"); 436 snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX");
406 } 437 }
407 char* result; 438 char* result;
408 do { 439 do {
409 result = mkdtemp(path); 440 result = android_mkdtemp(path);
cshapiro 2012/08/07 20:56:54 ditto
jackpal 2012/08/07 21:43:26 Done.
410 } while (result == NULL && errno == EINTR); 441 } while (result == NULL && errno == EINTR);
411 if (result == NULL) { 442 if (result == NULL) {
412 free(path); 443 free(path);
413 return NULL; 444 return NULL;
414 } 445 }
415 return path; 446 return path;
416 } 447 }
417 448
cshapiro 2012/08/07 20:56:54 Definitions are separated by 2 spaces. You should
jackpal 2012/08/07 21:43:26 Done.
418
419 bool Directory::Delete(const char* dir_name, bool recursive) { 449 bool Directory::Delete(const char* dir_name, bool recursive) {
420 if (!recursive) { 450 if (!recursive) {
421 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); 451 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0);
422 } else { 452 } else {
423 return DeleteRecursively(dir_name); 453 return DeleteRecursively(dir_name);
424 } 454 }
425 } 455 }
426 456
427 457
428 bool Directory::Rename(const char* path, const char* new_path) { 458 bool Directory::Rename(const char* path, const char* new_path) {
429 ExistsResult exists = Exists(path); 459 ExistsResult exists = Exists(path);
430 if (exists != EXISTS) return false; 460 if (exists != EXISTS) return false;
431 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 461 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
432 } 462 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698