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

Side by Side Diff: runtime/bin/directory_linux.cc

Issue 15719002: Provide a POSIX-compliant implementation of Directory::Current. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
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 = 1024;
Søren Gjesse 2013/05/22 14:39:34 Use an initial size of PATH_MAX?
podivilov 2013/05/22 17:05:13 Done.
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
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)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698