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

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

Issue 10824159: 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
379 return getcwd(NULL, 0); 384 return getcwd(NULL, 0);
385
386 #else
387
388 // POSIX getcwd requires a pre-allocated buffer.
389
390 char buffer[PATH_MAX];
391 if (NULL == getcwd(buffer, PATH_MAX)) {
392 return NULL;
393 }
394
395 size_t length = strlen(buffer) + 1;
396 char* result = reinterpret_cast<char*>(malloc(length));
397 if (result == NULL) {
398 return NULL;
399 }
400
401 strncpy(result, buffer, length);
402 return result;
403
404 #else
405 #endif
380 } 406 }
381 407
382 408
383 bool Directory::Create(const char* dir_name) { 409 bool Directory::Create(const char* dir_name) {
384 // Create the directory with the permissions specified by the 410 // Create the directory with the permissions specified by the
385 // process umask. 411 // process umask.
386 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0); 412 return (TEMP_FAILURE_RETRY(mkdir(dir_name, 0777)) == 0);
387 } 413 }
388 414
389 415
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return DeleteRecursively(dir_name); 449 return DeleteRecursively(dir_name);
424 } 450 }
425 } 451 }
426 452
427 453
428 bool Directory::Rename(const char* path, const char* new_path) { 454 bool Directory::Rename(const char* path, const char* new_path) {
429 ExistsResult exists = Exists(path); 455 ExistsResult exists = Exists(path);
430 if (exists != EXISTS) return false; 456 if (exists != EXISTS) return false;
431 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); 457 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0);
432 } 458 }
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