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 | 1522fce477f3b6b1b5812aa561ad2ff3f51eb968 (patch) | |
tree | 7091ae78128def7a19269ea17f9f9632ab220d45 /lib/Support | |
parent | 3890e397c3fa6cc11f50ea5e32ca81afa1e653a5 (diff) |
Support/PathV2: Move current_path from path to fs and fix the Unix implementation.
Unix bug spotted by Dan Gohman.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@121090 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r-- | lib/Support/PathV2.cpp | 2 | ||||
-rw-r--r-- | lib/Support/Unix/PathV2.inc | 24 | ||||
-rw-r--r-- | lib/Support/Windows/PathV2.inc | 6 |
3 files changed, 15 insertions, 17 deletions
diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 639b323a82..492903e4b5 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -437,7 +437,7 @@ error_code make_absolute(SmallVectorImpl<char> &path) { // All of the following conditions will need the current directory. SmallString<128> current_dir; - if (error_code ec = current_path(current_dir)) return ec; + if (error_code ec = fs::current_path(current_dir)) return ec; // Relative path. Prepend the current directory. if (!rootName && !rootDirectory) { diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc index b5cf724c5f..f7ca64daf7 100644 --- a/lib/Support/Unix/PathV2.inc +++ b/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; diff --git a/lib/Support/Windows/PathV2.inc b/lib/Support/Windows/PathV2.inc index c724607453..ff90515345 100644 --- a/lib/Support/Windows/PathV2.inc +++ b/lib/Support/Windows/PathV2.inc @@ -134,7 +134,7 @@ namespace { namespace llvm { namespace sys { -namespace path { +namespace fs { error_code current_path(SmallVectorImpl<char> &result) { SmallVector<wchar_t, 128> cur_path; @@ -180,10 +180,6 @@ retry_cur_dir: 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; |