summaryrefslogtreecommitdiffstats
path: root/lldb/source/Host/windows/FileSystem.cpp
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2017-03-21 04:45:10 +0000
committerJason Molenda <jmolenda@apple.com>2017-03-21 04:45:10 +0000
commit2eb3227f97e9ed5d086a9cc80f9ed590e8a1ff93 (patch)
treef27e0e5634a00556430f635e843a97543abc6b81 /lldb/source/Host/windows/FileSystem.cpp
parent3724ae4e7092c8145e22f5f1fbe4825c0682b907 (diff)
downloadbcm5719-llvm-2eb3227f97e9ed5d086a9cc80f9ed590e8a1ff93.tar.gz
bcm5719-llvm-2eb3227f97e9ed5d086a9cc80f9ed590e8a1ff93.zip
Revert r298334 until Zachary has a chance to fix the buildbot failure
on macosx. llvm-svn: 298338
Diffstat (limited to 'lldb/source/Host/windows/FileSystem.cpp')
-rw-r--r--lldb/source/Host/windows/FileSystem.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/lldb/source/Host/windows/FileSystem.cpp b/lldb/source/Host/windows/FileSystem.cpp
index 907c0c9337a..e834c85a28c 100644
--- a/lldb/source/Host/windows/FileSystem.cpp
+++ b/lldb/source/Host/windows/FileSystem.cpp
@@ -26,6 +26,49 @@ const char *FileSystem::DEV_NULL = "nul";
const char *FileSystem::PATH_CONVERSION_ERROR =
"Error converting path between UTF-8 and native encoding";
+FileSpec::PathSyntax FileSystem::GetNativePathSyntax() {
+ return FileSpec::ePathSyntaxWindows;
+}
+
+lldb::user_id_t FileSystem::GetFileSize(const FileSpec &file_spec) {
+ return file_spec.GetByteSize();
+}
+
+bool FileSystem::GetFileExists(const FileSpec &file_spec) {
+ return file_spec.Exists();
+}
+
+Error FileSystem::Hardlink(const FileSpec &src, const FileSpec &dst) {
+ Error error;
+ std::wstring wsrc, wdst;
+ if (!llvm::ConvertUTF8toWide(src.GetCString(), wsrc) ||
+ !llvm::ConvertUTF8toWide(dst.GetCString(), wdst))
+ error.SetErrorString(PATH_CONVERSION_ERROR);
+ else if (!::CreateHardLinkW(wsrc.c_str(), wdst.c_str(), nullptr))
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
+int FileSystem::GetHardlinkCount(const FileSpec &file_spec) {
+ std::wstring path;
+ if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path))
+ return -1;
+
+ HANDLE file_handle =
+ ::CreateFileW(path.c_str(), FILE_READ_ATTRIBUTES, FILE_SHARE_READ,
+ nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+
+ if (file_handle == INVALID_HANDLE_VALUE)
+ return -1;
+
+ AutoHandle auto_file_handle(file_handle);
+ BY_HANDLE_FILE_INFORMATION file_info;
+ if (::GetFileInformationByHandle(file_handle, &file_info))
+ return file_info.nNumberOfLinks;
+
+ return -1;
+}
+
Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
Error error;
std::wstring wsrc, wdst;
@@ -47,6 +90,19 @@ Error FileSystem::Symlink(const FileSpec &src, const FileSpec &dst) {
return error;
}
+Error FileSystem::Unlink(const FileSpec &file_spec) {
+ Error error;
+ std::wstring path;
+ if (!llvm::ConvertUTF8toWide(file_spec.GetCString(), path)) {
+ error.SetErrorString(PATH_CONVERSION_ERROR);
+ return error;
+ }
+ BOOL result = ::DeleteFileW(path.c_str());
+ if (!result)
+ error.SetError(::GetLastError(), lldb::eErrorTypeWin32);
+ return error;
+}
+
Error FileSystem::Readlink(const FileSpec &src, FileSpec &dst) {
Error error;
std::wstring wsrc;
@@ -84,6 +140,15 @@ Error FileSystem::ResolveSymbolicLink(const FileSpec &src, FileSpec &dst) {
return Error("ResolveSymbolicLink() isn't implemented on Windows");
}
+bool FileSystem::IsLocal(const FileSpec &spec) {
+ if (spec) {
+ // TODO: return true if the file is on a locally mounted file system
+ return true;
+ }
+
+ return false;
+}
+
FILE *FileSystem::Fopen(const char *path, const char *mode) {
std::wstring wpath, wmode;
if (!llvm::ConvertUTF8toWide(path, wpath))
@@ -95,3 +160,25 @@ FILE *FileSystem::Fopen(const char *path, const char *mode) {
return nullptr;
return file;
}
+
+int FileSystem::Stat(const char *path, struct stat *stats) {
+ std::wstring wpath;
+ if (!llvm::ConvertUTF8toWide(path, wpath)) {
+ errno = EINVAL;
+ return -EINVAL;
+ }
+ int stat_result;
+#ifdef _USE_32BIT_TIME_T
+ struct _stat32 file_stats;
+ stat_result = ::_wstat32(wpath.c_str(), &file_stats);
+#else
+ struct _stat64i32 file_stats;
+ stat_result = ::_wstat64i32(wpath.c_str(), &file_stats);
+#endif
+ if (stat_result == 0) {
+ static_assert(sizeof(struct stat) == sizeof(file_stats),
+ "stat and _stat32/_stat64i32 must have the same layout");
+ *stats = *reinterpret_cast<struct stat *>(&file_stats);
+ }
+ return stat_result;
+}
OpenPOWER on IntegriCloud