mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-09-07 16:54:48 +00:00
Improve sys::Path::makeAbsolute on Win32.
- Patch by Viktor Kutuzov! - Minor tweak by me to add llvm_unreachable calls on FIXMEd error paths. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75424 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f36892335b
commit
a00e85c9b1
@ -51,7 +51,7 @@ sys::Path llvm::FindExecutable(const std::string &ExeName,
|
|||||||
|
|
||||||
// Otherwise check the directory that the calling program is in. We can do
|
// Otherwise check the directory that the calling program is in. We can do
|
||||||
// this if ProgramPath contains at least one / character, indicating that it
|
// this if ProgramPath contains at least one / character, indicating that it
|
||||||
// is a relative path to bugpoint itself.
|
// is a relative path to the executable itself.
|
||||||
Result = ProgramPath;
|
Result = ProgramPath;
|
||||||
Result.eraseComponent();
|
Result.eraseComponent();
|
||||||
if (!Result.isEmpty()) {
|
if (!Result.isEmpty()) {
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "llvm/System/Path.h"
|
#include "llvm/System/Path.h"
|
||||||
#include "llvm/Config/config.h"
|
#include "llvm/Config/config.h"
|
||||||
|
#include "llvm/Support/ErrorHandling.h"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -207,18 +208,6 @@ bool Path::hasMagicNumber(const std::string &Magic) const {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Path::makeAbsolute() {
|
|
||||||
if (isAbsolute())
|
|
||||||
return;
|
|
||||||
|
|
||||||
Path CWD = Path::GetCurrentDirectory();
|
|
||||||
assert(CWD.isAbsolute() && "GetCurrentDirectory returned relative path!");
|
|
||||||
|
|
||||||
CWD.appendComponent(path);
|
|
||||||
|
|
||||||
path = CWD.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void getPathList(const char*path, std::vector<Path>& Paths) {
|
static void getPathList(const char*path, std::vector<Path>& Paths) {
|
||||||
const char* at = path;
|
const char* at = path;
|
||||||
const char* delim = strchr(at, PathSeparator);
|
const char* delim = strchr(at, PathSeparator);
|
||||||
|
@ -109,6 +109,19 @@ Path::isAbsolute() const {
|
|||||||
return false;
|
return false;
|
||||||
return path[0] == '/';
|
return path[0] == '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Path::makeAbsolute() {
|
||||||
|
if (isAbsolute())
|
||||||
|
return;
|
||||||
|
|
||||||
|
Path CWD = Path::GetCurrentDirectory();
|
||||||
|
assert(CWD.isAbsolute() && "GetCurrentDirectory returned relative path!");
|
||||||
|
|
||||||
|
CWD.appendComponent(path);
|
||||||
|
|
||||||
|
path = CWD.toString();
|
||||||
|
}
|
||||||
|
|
||||||
Path
|
Path
|
||||||
Path::GetRootDirectory() {
|
Path::GetRootDirectory() {
|
||||||
Path result;
|
Path result;
|
||||||
|
@ -125,9 +125,30 @@ Path::isValid() const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Path::makeAbsolute() {
|
||||||
|
TCHAR FullPath[MAX_PATH + 1] = {0};
|
||||||
|
LPTSTR FilePart = NULL;
|
||||||
|
|
||||||
|
DWORD RetLength = ::GetFullPathNameA(path.c_str(),
|
||||||
|
sizeof(FullPath)/sizeof(FullPath[0]),
|
||||||
|
FullPath, &FilePart);
|
||||||
|
|
||||||
|
if (0 == RetLength) {
|
||||||
|
// FIXME: Report the error GetLastError()
|
||||||
|
llvm_unreachable("Unable to make absolute path!");
|
||||||
|
} else if (RetLength > MAX_PATH) {
|
||||||
|
// FIXME: Report too small buffer (needed RetLength bytes).
|
||||||
|
llvm_unreachable("Unable to make absolute path!");
|
||||||
|
} else {
|
||||||
|
path = FullPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isAbsolute(const char *NameStart, unsigned NameLen) {
|
Path::isAbsolute(const char *NameStart, unsigned NameLen) {
|
||||||
assert(NameStart);
|
assert(NameStart);
|
||||||
|
// FIXME: This does not handle correctly an absolute path starting from
|
||||||
|
// a drive letter or in UNC format.
|
||||||
switch (NameLen) {
|
switch (NameLen) {
|
||||||
case 0:
|
case 0:
|
||||||
return false;
|
return false;
|
||||||
@ -141,6 +162,8 @@ Path::isAbsolute(const char *NameStart, unsigned NameLen) {
|
|||||||
|
|
||||||
bool
|
bool
|
||||||
Path::isAbsolute() const {
|
Path::isAbsolute() const {
|
||||||
|
// FIXME: This does not handle correctly an absolute path starting from
|
||||||
|
// a drive letter or in UNC format.
|
||||||
switch (path.length()) {
|
switch (path.length()) {
|
||||||
case 0:
|
case 0:
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user