diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-07 01:22:31 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2010-12-07 01:22:31 +0000 |
commit | 20daa28344d24e9e6f72140c7eca220dfe56b7cd (patch) | |
tree | 2d017abf51b8f6c24d4a53fafeef159334308ed1 /llvm/lib/Support/Unix/PathV2.inc | |
parent | 166f25d3218af1656cb597cb5965d33df046c49c (diff) | |
download | bcm5719-llvm-20daa28344d24e9e6f72140c7eca220dfe56b7cd.tar.gz bcm5719-llvm-20daa28344d24e9e6f72140c7eca220dfe56b7cd.zip |
Support/PathV2: Move current_path from path to fs and fix the Unix implementation.
Unix bug spotted by Dan Gohman.
llvm-svn: 121090
Diffstat (limited to 'llvm/lib/Support/Unix/PathV2.inc')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index b5cf724c5ff..f7ca64daf7e 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -69,24 +69,26 @@ namespace { namespace llvm { namespace sys { -namespace path { +namespace fs { error_code current_path(SmallVectorImpl<char> &result) { - long size = ::pathconf(".", _PC_PATH_MAX); - result.reserve(size + 1); - result.set_size(size + 1); - - if (::getcwd(result.data(), result.size()) == 0) - return error_code(errno, system_category()); + result.reserve(MAXPATHLEN); + + while (true) { + if (::getcwd(result.data(), result.capacity()) == 0) { + // See if there was a real error. + if (errno != errc::not_enough_memory) + return error_code(errno, system_category()); + // Otherwise there just wasn't enough space. + result.reserve(result.capacity() * 2); + } else + break; + } result.set_size(strlen(result.data())); return success; } -} // end namespace path - -namespace fs{ - error_code copy_file(const Twine &from, const Twine &to, copy_option copt) { // Get arguments. SmallString<128> from_storage; |