| 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
| 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 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 409 ASSERT(errno == ELOOP || | 409 ASSERT(errno == ELOOP || |
| 410 errno == ENAMETOOLONG || | 410 errno == ENAMETOOLONG || |
| 411 errno == ENOENT || | 411 errno == ENOENT || |
| 412 errno == ENOTDIR); | 412 errno == ENOTDIR); |
| 413 return DOES_NOT_EXIST; | 413 return DOES_NOT_EXIST; |
| 414 } | 414 } |
| 415 } | 415 } |
| 416 | 416 |
| 417 | 417 |
| 418 char* Directory::Current() { | 418 char* Directory::Current() { |
| 419 return getcwd(NULL, 0); | 419 size_t size = PATH_MAX; |
| 420 char* buffer = NULL; |
| 421 for (char* result = NULL; result == NULL; size *= 2) { |
| 422 if ((buffer = reinterpret_cast<char*>(realloc(buffer, size))) == NULL) { |
| 423 return NULL; |
| 424 } |
| 425 result = getcwd(buffer, size); |
| 426 if (result == NULL && errno != ERANGE) { |
| 427 return NULL; |
| 428 } |
| 429 } |
| 430 return buffer; |
| 420 } | 431 } |
| 421 | 432 |
| 422 | 433 |
| 423 bool Directory::SetCurrent(const char* path) { | 434 bool Directory::SetCurrent(const char* path) { |
| 424 int result = TEMP_FAILURE_RETRY(chdir(path)); | 435 int result = TEMP_FAILURE_RETRY(chdir(path)); |
| 425 return result == 0; | 436 return result == 0; |
| 426 } | 437 } |
| 427 | 438 |
| 428 | 439 |
| 429 bool Directory::Create(const char* dir_name) { | 440 bool Directory::Create(const char* dir_name) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 bool Directory::Rename(const char* path, const char* new_path) { | 500 bool Directory::Rename(const char* path, const char* new_path) { |
| 490 ExistsResult exists = Exists(path); | 501 ExistsResult exists = Exists(path); |
| 491 if (exists != EXISTS) return false; | 502 if (exists != EXISTS) return false; |
| 492 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 503 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
| 493 } | 504 } |
| 494 | 505 |
| 495 } // namespace bin | 506 } // namespace bin |
| 496 } // namespace dart | 507 } // namespace dart |
| 497 | 508 |
| 498 #endif // defined(TARGET_OS_LINUX) | 509 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |