[llvm-commits] [llvm] r121090 - in /llvm/trunk: include/llvm/Support/FileSystem.h include/llvm/Support/PathV2.h lib/Support/PathV2.cpp lib/Support/Unix/PathV2.inc lib/Support/Windows/PathV2.inc
Michael J. Spencer
bigcheesegs at gmail.com
Mon Dec 6 17:22:31 PST 2010
Author: mspencer
Date: Mon Dec 6 19:22:31 2010
New Revision: 121090
URL: http://llvm.org/viewvc/llvm-project?rev=121090&view=rev
Log:
Support/PathV2: Move current_path from path to fs and fix the Unix implementation.
Unix bug spotted by Dan Gohman.
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/include/llvm/Support/PathV2.h
llvm/trunk/lib/Support/PathV2.cpp
llvm/trunk/lib/Support/Unix/PathV2.inc
llvm/trunk/lib/Support/Windows/PathV2.inc
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=121090&r1=121089&r2=121090&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Mon Dec 6 19:22:31 2010
@@ -148,6 +148,13 @@
/// otherwise a platform specific error_code.
error_code create_symlink(const Twine &to, const Twine &from);
+/// @brief Get the current path.
+///
+/// @param result Holds the current path on return.
+/// @results errc::success if the current path has been stored in result,
+/// otherwise a platform specific error_code.
+error_code current_path(SmallVectorImpl<char> &result);
+
/// @brief Remove path. Equivalent to POSIX remove().
///
/// @param path Input path.
Modified: llvm/trunk/include/llvm/Support/PathV2.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/PathV2.h?rev=121090&r1=121089&r2=121090&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/PathV2.h (original)
+++ llvm/trunk/include/llvm/Support/PathV2.h Mon Dec 6 19:22:31 2010
@@ -202,15 +202,6 @@
/// @name Lexical Observers
/// @{
-/// @brief Get the current path.
-///
-/// @param result Holds the current path on return.
-/// @results errc::success if the current path has been stored in result,
-/// otherwise a platform specific error_code.
-error_code current_path(SmallVectorImpl<char> &result);
-
-// The following are purely lexical.
-
/// @brief Get root name.
///
/// //net/hello => //net
Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=121090&r1=121089&r2=121090&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Mon Dec 6 19:22:31 2010
@@ -437,7 +437,7 @@
// 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) {
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=121090&r1=121089&r2=121090&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Mon Dec 6 19:22:31 2010
@@ -69,24 +69,26 @@
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);
+ result.reserve(MAXPATHLEN);
- if (::getcwd(result.data(), result.size()) == 0)
- return error_code(errno, system_category());
+ 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;
Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=121090&r1=121089&r2=121090&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Mon Dec 6 19:22:31 2010
@@ -134,7 +134,7 @@
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 @@
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;
More information about the llvm-commits
mailing list