Implement FileSystem::GetPermissions for Windows. Differential Revision: http://reviews.llvm.org/D11303

llvm-svn: 242568
This commit is contained in:
Adrian McCarthy 2015-07-17 20:23:03 +00:00
parent cab8980229
commit 633594c261
1 changed files with 19 additions and 1 deletions

View File

@ -10,6 +10,8 @@
#include "lldb/Host/windows/windows.h"
#include <shellapi.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "lldb/Host/FileSystem.h"
#include "llvm/Support/FileSystem.h"
@ -71,7 +73,23 @@ Error
FileSystem::GetFilePermissions(const FileSpec &file_spec, uint32_t &file_permissions)
{
Error error;
error.SetErrorStringWithFormat("%s is not supported on this host", __PRETTY_FUNCTION__);
// Beware that Windows's permission model is different from Unix's, and it's
// not clear if this API is supposed to check ACLs. To match the caller's
// expectations as closely as possible, we'll use Microsoft's _stat, which
// attempts to emulate POSIX stat. This should be good enough for basic
// checks like FileSpec::Readable.
struct _stat file_stats;
if (::_stat(file_spec.GetCString(), &file_stats) == 0)
{
// The owner permission bits in "st_mode" currently match the definitions
// for the owner file mode bits.
file_permissions = file_stats.st_mode & (_S_IREAD | _S_IWRITE | _S_IEXEC);
}
else
{
error.SetErrorToErrno();
}
return error;
}