[llvm] r184233 - Add a can_write function to PathV2.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jun 18 13:56:38 PDT 2013
Author: rafael
Date: Tue Jun 18 15:56:38 2013
New Revision: 184233
URL: http://llvm.org/viewvc/llvm-project?rev=184233&view=rev
Log:
Add a can_write function to PathV2.
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
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=184233&r1=184232&r2=184233&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Tue Jun 18 15:56:38 2013
@@ -356,6 +356,12 @@ inline bool exists(const Twine &path) {
/// @returns True if we can execute it, false otherwise.
bool can_execute(const Twine &Path);
+/// @brief Can we write this file?
+///
+/// @param Path Input path.
+/// @returns True if we can write to it, false otherwise.
+bool can_write(const Twine &Path);
+
/// @brief Do file_status's represent the same thing?
///
/// @param A Input file_status.
Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=184233&r1=184232&r2=184233&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Tue Jun 18 15:56:38 2013
@@ -308,6 +308,12 @@ error_code exists(const Twine &path, boo
return error_code::success();
}
+bool can_write(const Twine &Path) {
+ SmallString<128> PathStorage;
+ StringRef P = Path.toNullTerminatedStringRef(PathStorage);
+ return 0 == access(P.begin(), W_OK);
+}
+
bool can_execute(const Twine &Path) {
SmallString<128> PathStorage;
StringRef P = Path.toNullTerminatedStringRef(PathStorage);
Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=184233&r1=184232&r2=184233&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Tue Jun 18 15:56:38 2013
@@ -362,6 +362,18 @@ error_code exists(const Twine &path, boo
return error_code::success();
}
+bool can_write(const Twine &Path) {
+ // FIXME: take security attributes into account.
+ SmallString<128> PathStorage;
+ SmallVector<wchar_t, 128> PathUtf16;
+
+ if (UTF8ToUTF16(Path.toStringRef(PathStorage), PathUtf16))
+ return false;
+
+ DWORD Attr = ::GetFileAttributesW(PathUtf16.begin());
+ return (Attr != INVALID_FILE_ATTRIBUTES) && !(Attr & FILE_ATTRIBUTE_READONLY);
+}
+
bool can_execute(const Twine &Path) {
SmallString<128> PathStorage;
SmallVector<wchar_t, 128> PathUtf16;
More information about the llvm-commits
mailing list