diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-18 20:56:38 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-18 20:56:38 +0000 |
commit | a1280c16fb012fb167787a7c99d526bc19153dcc (patch) | |
tree | 5c4e2e3285a13b6ffa94b149b6e751a98a5c2216 /llvm/lib/Support/Windows/PathV2.inc | |
parent | 8f99e9413f49f89d1c29e1c083068b9aedbbee4e (diff) | |
download | bcm5719-llvm-a1280c16fb012fb167787a7c99d526bc19153dcc.tar.gz bcm5719-llvm-a1280c16fb012fb167787a7c99d526bc19153dcc.zip |
Add a can_write function to PathV2.
llvm-svn: 184233
Diffstat (limited to 'llvm/lib/Support/Windows/PathV2.inc')
-rw-r--r-- | llvm/lib/Support/Windows/PathV2.inc | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc index 3b2992d5a30..bec95e36cc5 100644 --- a/llvm/lib/Support/Windows/PathV2.inc +++ b/llvm/lib/Support/Windows/PathV2.inc @@ -362,6 +362,18 @@ error_code exists(const Twine &path, bool &result) { 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; |