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

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

Issue 10828180: Revert "Make Directory::Current() work with unenhanced POSIX getcwd" (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
« 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 "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 #if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOS)
380
381 // On targets that support it, let getcwd allocate the buffer
382 // dynamically. (Not part of POSIX, but implemented on many platforms.)
383 return getcwd(NULL, 0); 379 return getcwd(NULL, 0);
384
385 #else
386
387 // POSIX getcwd requires a pre-allocated buffer.
388 char buffer[PATH_MAX];
389 if (NULL == getcwd(buffer, PATH_MAX)) {
390 return NULL;
391 }
392
393 size_t length = strlen(buffer) + 1;
394 char* result = reinterpret_cast<char*>(malloc(length));
395 if (result == NULL) {
396 return NULL;
397 }
398
399 strncpy(result, buffer, length);
400 return result;
401
402 #endif
403 } 380 }
404 381
405 382
406 bool Directory::Create(const char* dir_name) { 383 bool Directory::Create(const char* dir_name) {
407 // Create the directory with the permissions specified by the 384 // Create the directory with the permissions specified by the
408 // process umask. 385 // process umask.
409 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); 386 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0);
410 } 387 }
411 388
412 389
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 return DeleteRecursively(dir_name); 423 return DeleteRecursively(dir_name);
447 } 424 }
448 } 425 }
449 426
450 427
451 bool Directory::Rename(const char* path, const char* new_path) { 428 bool Directory::Rename(const char* path, const char* new_path) {
452 ExistsResult exists = Exists(path); 429 ExistsResult exists = Exists(path);
453 if (exists != EXISTS) return false; 430 if (exists != EXISTS) return false;
454 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 431 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
455 } 432 }
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