20#include "llvm/Support/ConvertUTF.h"
21#include "llvm/Support/FileSystem.h"
28 "Error converting path between UTF-8 and native encoding";
32 std::wstring wsrc, wdst;
33 if (!llvm::ConvertUTF8toWide(src.
GetPath(), wsrc) ||
34 !llvm::ConvertUTF8toWide(dst.
GetPath(), wdst))
38 DWORD attrib = ::GetFileAttributesW(wdst.c_str());
39 if (attrib == INVALID_FILE_ATTRIBUTES) {
43 bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY);
44 DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
45 BOOL result = ::CreateSymbolicLinkW(wsrc.c_str(), wdst.c_str(), flag);
54 if (!llvm::ConvertUTF8toWide(src.
GetPath(), wsrc)) {
59 HANDLE h = ::CreateFileW(wsrc.c_str(), GENERIC_READ,
60 FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
61 OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT, NULL);
62 if (h == INVALID_HANDLE_VALUE) {
67 std::vector<wchar_t> buf(
PATH_MAX + 1);
70 DWORD result = ::GetFinalPathNameByHandleW(
71 h, buf.data(), buf.size() - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
75 else if (!llvm::convertWideToUTF8(buf.data(), path))
78 dst.
SetFile(path, FileSpec::Style::native);
85 return Status(
"ResolveSymbolicLink() isn't implemented on Windows");
89 std::wstring wpath, wmode;
90 if (!llvm::ConvertUTF8toWide(path, wpath))
92 if (!llvm::ConvertUTF8toWide(mode, wmode))
95 if (_wfopen_s(&file, wpath.c_str(), wmode.c_str()) != 0)
102 if (!llvm::ConvertUTF8toWide(path, wpath))
105 mode = mode & (_S_IREAD | _S_IWRITE);
107 ::_wsopen_s(&result, wpath.c_str(), 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.
A class that represents a running process on the host machine.
@ eErrorTypeWin32
Standard Win32 error codes.