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

Side by Side Diff: runtime/bin/directory_linux.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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 char* Directory::Current() { 378 char* Directory::Current() {
379 return getcwd(NULL, 0); 379 return getcwd(NULL, 0);
380 } 380 }
381 381
382 382
383 bool Directory::Create(const char* dir_name) { 383 bool Directory::Create(const char* dir_name) {
384 // Create the directory with the permissions specified by the 384 // Create the directory with the permissions specified by the
385 // process umask. 385 // process umask.
386 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); 386 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0);
387 } 387 }
388 388
cshapiro 2012/08/07 20:56:54 2 spaces between definitions.
jackpal 2012/08/07 21:43:26 Done.
389
390 char* Directory::CreateTemp(const char* const_template) { 389 char* Directory::CreateTemp(const char* const_template) {
391 // Returns a new, unused directory name, modifying the contents of 390 // Returns a new, unused directory name, modifying the contents of
392 // dir_template. Creates the directory with the permissions specified 391 // dir_template. Creates the directory with the permissions specified
393 // by the process umask. 392 // by the process umask.
394 // The return value must be freed by the caller. 393 // The return value must be freed by the caller.
395 char* path = static_cast<char*>(malloc(PATH_MAX + 1)); 394 char* path = static_cast<char*>(malloc(PATH_MAX + 1));
396 SafeStrNCpy(path, const_template, PATH_MAX + 1); 395 SafeStrNCpy(path, const_template, PATH_MAX + 1);
397 int path_length = strlen(path); 396 int path_length = strlen(path);
398 if (path_length > 0) { 397 if (path_length > 0) {
399 if ((path)[path_length - 1] == '/') { 398 if ((path)[path_length - 1] == '/') {
400 snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX"); 399 snprintf(path + path_length, PATH_MAX - path_length, "temp_dir_XXXXXX");
401 } else { 400 } else {
402 snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX"); 401 snprintf(path + path_length, PATH_MAX - path_length, "XXXXXX");
403 } 402 }
404 } else { 403 } else {
405 snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX"); 404 snprintf(path, PATH_MAX, "/tmp/temp_dir1_XXXXXX");
406 } 405 }
407 char* result; 406 char* result;
408 do { 407 do {
409 result = mkdtemp(path); 408 result = mkdtemp(path);
410 } while (result == NULL && errno == EINTR); 409 } while (result == NULL && errno == EINTR);
411 if (result == NULL) { 410 if (result == NULL) {
412 free(path); 411 free(path);
413 return NULL; 412 return NULL;
414 } 413 }
415 return path; 414 return path;
416 } 415 }
417 416
cshapiro 2012/08/07 20:56:54 Ditto.
jackpal 2012/08/07 21:43:26 Done.
418
419 bool Directory::Delete(const char* dir_name, bool recursive) { 417 bool Directory::Delete(const char* dir_name, bool recursive) {
420 if (!recursive) { 418 if (!recursive) {
421 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0); 419 return (TEMP_FAILURE_RETRY(remove(dir_name)) == 0);
422 } else { 420 } else {
423 return DeleteRecursively(dir_name); 421 return DeleteRecursively(dir_name);
424 } 422 }
425 } 423 }
426 424
427 425
428 bool Directory::Rename(const char* path, const char* new_path) { 426 bool Directory::Rename(const char* path, const char* new_path) {
429 ExistsResult exists = Exists(path); 427 ExistsResult exists = Exists(path);
430 if (exists != EXISTS) return false; 428 if (exists != EXISTS) return false;
431 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 429 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
432 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698