21#include "llvm/Support/ConvertUTF.h"
22#include "llvm/Support/FileSystem.h"
23#include "llvm/Support/Path.h"
24#include "llvm/Support/Windows/WindowsSupport.h"
31 "Error converting path between UTF-8 and native encoding";
35 llvm::SmallVector<wchar_t, MAX_PATH> wsrc, wdst_long;
37 if (llvm::sys::windows::widenPath(src.
GetPath(), wsrc) ||
38 llvm::sys::windows::widenPath(dst.
GetPath(), wdst_long) ||
39 !llvm::ConvertUTF8toWide(dst.
GetPath(), wdst))
43 DWORD attrib = ::GetFileAttributesW(wdst_long.data());
44 if (attrib == INVALID_FILE_ATTRIBUTES) {
48 bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY);
49 DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
53 const wchar_t *target = llvm::sys::path::is_absolute(dst.
GetPath())
56 BOOL result = ::CreateSymbolicLinkW(wsrc.data(), target, flag);
64 llvm::SmallVector<wchar_t, MAX_PATH> wsrc;
65 if (llvm::sys::windows::widenPath(src.
GetPath(), wsrc)) {
71 wsrc.data(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
72 OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT,
nullptr);
73 if (h == INVALID_HANDLE_VALUE) {
78 llvm::SmallVector<wchar_t, MAX_PATH> buf(
MAX_PATH + 1);
81 DWORD result = ::GetFinalPathNameByHandleW(
82 h, buf.data(), buf.size() - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
83 while (result >= buf.size() - 1) {
84 buf.resize(result + 1);
85 result = ::GetFinalPathNameByHandleW(
86 h, buf.data(), buf.size() - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
91 else if (!llvm::convertWideToUTF8(std::wstring(buf.data(), result), path))
102 "ResolveSymbolicLink() isn't implemented on Windows");
106 llvm::SmallVector<wchar_t, MAX_PATH> wpath;
108 if (llvm::sys::windows::widenPath(path, wpath))
110 if (!llvm::ConvertUTF8toWide(mode, wmode))
113 if (_wfopen_s(&file, wpath.data(), wmode.c_str()) != 0)
119 llvm::SmallVector<wchar_t, MAX_PATH> wpath;
120 if (llvm::sys::windows::widenPath(path, wpath))
123 mode = mode & (_S_IREAD | _S_IWRITE);
125 ::_wsopen_s(&result, wpath.data(), flags, _SH_DENYNO, mode);
static llvm::raw_ostream & error(Stream &strm)
void SetFile(llvm::StringRef path, Style style)
Change the file specified with a new path.
size_t GetPath(char *path, size_t max_path_length, bool denormalize=true) const
Extract the full path to the file.
static const char * PATH_CONVERSION_ERROR
static const char * DEV_NULL
Status Symlink(const FileSpec &src, const FileSpec &dst)
Status ResolveSymbolicLink(const FileSpec &src, FileSpec &dst)
int Open(const char *path, int flags, int mode=0600)
Wraps open in a platform-independent way.
Status Readlink(const FileSpec &src, FileSpec &dst)
FILE * Fopen(const char *path, const char *mode)
Wraps fopen in a platform-independent way.
static Status FromErrorString(const char *str)
A class that represents a running process on the host machine.
std::string StripExtendedLengthPrefix(llvm::StringRef path)
Convert an extended-length path to a regular DOS path: "\\?\C:\a" becomes "C:\a" and "\\?...
@ eErrorTypeWin32
Standard Win32 error codes.