mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-28 07:05:03 +00:00
Add a can_write function to PathV2.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184233 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
41502e1af7
commit
68ba1825fc
@ -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.
|
||||
|
@ -308,6 +308,12 @@ error_code exists(const Twine &path, bool &result) {
|
||||
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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user