[llvm-commits] [llvm] r120790 - in /llvm/trunk/lib/Support: PathV2.cpp Unix/PathV2.inc Windows/PathV2.inc
Michael J. Spencer
bigcheesegs at gmail.com
Thu Dec 2 21:42:11 PST 2010
Author: mspencer
Date: Thu Dec 2 23:42:11 2010
New Revision: 120790
URL: http://llvm.org/viewvc/llvm-project?rev=120790&view=rev
Log:
Support/FileSystem: Add create_director{y,ies} implementations.
Modified:
llvm/trunk/lib/Support/PathV2.cpp
llvm/trunk/lib/Support/Unix/PathV2.inc
llvm/trunk/lib/Support/Windows/PathV2.inc
Modified: llvm/trunk/lib/Support/PathV2.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/PathV2.cpp?rev=120790&r1=120789&r2=120790&view=diff
==============================================================================
--- llvm/trunk/lib/Support/PathV2.cpp (original)
+++ llvm/trunk/lib/Support/PathV2.cpp Thu Dec 2 23:42:11 2010
@@ -671,6 +671,21 @@
namespace fs {
+error_code create_directories(const Twine &path, bool &existed) {
+ SmallString<128> path_storage;
+ StringRef p = path.toStringRef(path_storage);
+
+ StringRef parent;
+ bool parent_exists;
+ if (error_code ec = path::parent_path(p, parent)) return ec;
+ if (error_code ec = fs::exists(parent, parent_exists)) return ec;
+
+ if (!parent_exists)
+ return create_directories(parent, existed);
+
+ return create_directory(p, existed);
+}
+
} // end namespace fs
} // end namespace sys
} // end namespace llvm
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=120790&r1=120789&r2=120790&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Thu Dec 2 23:42:11 2010
@@ -146,6 +146,20 @@
return make_error_code(errc::success);
}
+error_code create_directory(const Twine &path, bool &existed) {
+ SmallString<128> path_storage;
+ StringRef p = path.toNullTerminatedStringRef(path_storage);
+
+ if (::mkdir(p.begin(), 0700) == -1) {
+ if (errno != EEXIST)
+ return error_code(errno, system_category());
+ existed = true;
+ } else
+ existed = false;
+
+ return make_error_code(errc::success);
+}
+
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
StringRef p = path.toNullTerminatedStringRef(path_storage);
Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=120790&r1=120789&r2=120790&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Thu Dec 2 23:42:11 2010
@@ -181,6 +181,26 @@
return make_error_code(errc::success);
}
+error_code create_directory(const Twine &path, bool &existed) {
+ SmallString<128> path_storage;
+ SmallVector<wchar_t, 128> path_utf16;
+
+ if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
+ path_utf16))
+ return ec;
+
+ if (!::CreateDirectoryW(path_utf16.begin(), NULL)) {
+ error_code ec = make_error_code(windows_error(::GetLastError()));
+ if (ec == make_error_code(windows_error::already_exists))
+ existed = true;
+ else
+ return ec;
+ } else
+ existed = false;
+
+ return make_error_code(errc::success);
+}
+
error_code exists(const Twine &path, bool &result) {
SmallString<128> path_storage;
SmallVector<wchar_t, 128> path_utf16;
More information about the llvm-commits
mailing list