21#include "llvm/Support/ConvertUTF.h"
22#include "llvm/Support/FileSystem.h"
29 "Error converting path between UTF-8 and native encoding";
33 std::wstring wsrc, wdst;
34 if (!llvm::ConvertUTF8toWide(src.
GetPath(), wsrc) ||
35 !llvm::ConvertUTF8toWide(dst.
GetPath(), wdst))
39 DWORD attrib = ::GetFileAttributesW(wdst.c_str());
40 if (attrib == INVALID_FILE_ATTRIBUTES) {
44 bool is_directory = !!(attrib & FILE_ATTRIBUTE_DIRECTORY);
45 DWORD flag = is_directory ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0;
46 BOOL result = ::CreateSymbolicLinkW(wsrc.c_str(), wdst.c_str(), flag);
55 if (!llvm::ConvertUTF8toWide(src.
GetPath(), wsrc)) {
61 wsrc.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr,
62 OPEN_EXISTING, FILE_FLAG_OPEN_REPARSE_POINT,
nullptr);
63 if (h == INVALID_HANDLE_VALUE) {
68 std::vector<wchar_t> buf(
PATH_MAX + 1);
71 DWORD result = ::GetFinalPathNameByHandleW(
72 h, buf.data(), buf.size() - 1, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
76 else if (!llvm::convertWideToUTF8(buf.data(), path))
87 "ResolveSymbolicLink() isn't implemented on Windows");
91 std::wstring wpath, wmode;
92 if (!llvm::ConvertUTF8toWide(path, wpath))
94 if (!llvm::ConvertUTF8toWide(mode, wmode))
97 if (_wfopen_s(&file, wpath.c_str(), wmode.c_str()) != 0)
104 if (!llvm::ConvertUTF8toWide(path, wpath))
107 mode = mode & (_S_IREAD | _S_IWRITE);
109 ::_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.
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.