diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2019-01-19 10:01:25 +0000 |
commit | d8e91e46262bc44006913e6796843909f1ac7bcd (patch) | |
tree | 7d0c143d9b38190e0fa0180805389da22cd834c5 /lib/Support/Windows/Program.inc | |
parent | b7eb8e35e481a74962664b63dfb09483b200209a (diff) |
Notes
Diffstat (limited to 'lib/Support/Windows/Program.inc')
-rw-r--r-- | lib/Support/Windows/Program.inc | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/Support/Windows/Program.inc b/lib/Support/Windows/Program.inc index cb68c5b10e52..c037956603f2 100644 --- a/lib/Support/Windows/Program.inc +++ b/lib/Support/Windows/Program.inc @@ -105,6 +105,25 @@ ErrorOr<std::string> sys::findProgramByName(StringRef Name, return std::string(U8Result.begin(), U8Result.end()); } +bool MakeErrMsg(std::string *ErrMsg, const std::string &prefix) { + if (!ErrMsg) + return true; + char *buffer = NULL; + DWORD LastError = GetLastError(); + DWORD R = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | + FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, LastError, 0, (LPSTR)&buffer, 1, NULL); + if (R) + *ErrMsg = prefix + ": " + buffer; + else + *ErrMsg = prefix + ": Unknown error"; + *ErrMsg += " (0x" + llvm::utohexstr(LastError) + ")"; + + LocalFree(buffer); + return R != 0; +} + static HANDLE RedirectIO(Optional<StringRef> Path, int fd, std::string *ErrMsg) { HANDLE h; @@ -317,7 +336,7 @@ static bool Execute(ProcessInfo &PI, StringRef Program, static bool argNeedsQuotes(StringRef Arg) { if (Arg.empty()) return true; - return StringRef::npos != Arg.find_first_of("\t \"&\'()*<>\\`^|"); + return StringRef::npos != Arg.find_first_of("\t \"&\'()*<>\\`^|\n"); } static std::string quoteSingleArg(StringRef Arg) { |