Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_ANDROID) | 6 #if defined(TARGET_OS_ANDROID) |
| 7 | 7 |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 | 9 |
| 10 #include <dirent.h> // NOLINT | 10 #include <dirent.h> // NOLINT |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 return DOES_NOT_EXIST; | 361 return DOES_NOT_EXIST; |
| 362 } | 362 } |
| 363 } | 363 } |
| 364 | 364 |
| 365 | 365 |
| 366 char* Directory::CurrentNoScope() { | 366 char* Directory::CurrentNoScope() { |
| 367 // Android's getcwd adheres closely to the POSIX standard. It won't | 367 // Android's getcwd adheres closely to the POSIX standard. It won't |
| 368 // allocate memory. We need to make our own copy. | 368 // allocate memory. We need to make our own copy. |
| 369 | 369 |
| 370 char buffer[PATH_MAX]; | 370 char buffer[PATH_MAX]; |
| 371 if (NULL == getcwd(buffer, PATH_MAX)) { | 371 if (getcwd(buffer, PATH_MAX) == NULL) { |
| 372 return NULL; | 372 return NULL; |
| 373 } | 373 } |
| 374 | 374 |
| 375 return strdup(buffer); | 375 return strdup(buffer); |
| 376 } | 376 } |
| 377 | 377 |
| 378 | 378 |
| 379 const char* Directory::Current() { | 379 const char* Directory::Current() { |
| 380 char* result = DartUtils::ScopedCString(PATH_MAX); | 380 char buffer[PATH_MAX]; |
|
zra
2016/03/15 18:12:29
Ported fix from Linux.
| |
| 381 ASSERT(result != NULL); | 381 if (getcwd(buffer, PATH_MAX) == NULL) { |
| 382 return getcwd(result, PATH_MAX); | 382 return NULL; |
| 383 } | |
| 384 return DartUtils::ScopedCopyCString(buffer); | |
| 383 } | 385 } |
| 384 | 386 |
| 385 | 387 |
| 386 bool Directory::SetCurrent(const char* path) { | 388 bool Directory::SetCurrent(const char* path) { |
| 387 int result = NO_RETRY_EXPECTED(chdir(path)); | 389 int result = NO_RETRY_EXPECTED(chdir(path)); |
| 388 return result == 0; | 390 return (result == 0); |
| 389 } | 391 } |
| 390 | 392 |
| 391 | 393 |
| 392 bool Directory::Create(const char* dir_name) { | 394 bool Directory::Create(const char* dir_name) { |
| 393 // Create the directory with the permissions specified by the | 395 // Create the directory with the permissions specified by the |
| 394 // process umask. | 396 // process umask. |
| 395 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); | 397 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); |
| 396 // If the directory already exists, treat it as a success. | 398 // If the directory already exists, treat it as a success. |
| 397 if ((result == -1) && (errno == EEXIST)) { | 399 if ((result == -1) && (errno == EEXIST)) { |
| 398 return (Exists(dir_name) == EXISTS); | 400 return (Exists(dir_name) == EXISTS); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 464 if (exists != EXISTS) { | 466 if (exists != EXISTS) { |
| 465 return false; | 467 return false; |
| 466 } | 468 } |
| 467 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 469 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
| 468 } | 470 } |
| 469 | 471 |
| 470 } // namespace bin | 472 } // namespace bin |
| 471 } // namespace dart | 473 } // namespace dart |
| 472 | 474 |
| 473 #endif // defined(TARGET_OS_ANDROID) | 475 #endif // defined(TARGET_OS_ANDROID) |
| OLD | NEW |