summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/lib/Support/Path.cpp')
-rw-r--r--contrib/llvm/lib/Support/Path.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/contrib/llvm/lib/Support/Path.cpp b/contrib/llvm/lib/Support/Path.cpp
index 4952f59..f6355d1 100644
--- a/contrib/llvm/lib/Support/Path.cpp
+++ b/contrib/llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/COFF.h"
+#include "llvm/Support/MachO.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
@@ -352,6 +353,10 @@ bool reverse_iterator::operator==(const reverse_iterator &RHS) const {
Position == RHS.Position;
}
+ptrdiff_t reverse_iterator::operator-(const reverse_iterator &RHS) const {
+ return Position - RHS.Position;
+}
+
StringRef root_path(StringRef path) {
const_iterator b = begin(path),
pos = b,
@@ -517,6 +522,29 @@ void replace_extension(SmallVectorImpl<char> &path, const Twine &extension) {
path.append(ext.begin(), ext.end());
}
+void replace_path_prefix(SmallVectorImpl<char> &Path,
+ const StringRef &OldPrefix,
+ const StringRef &NewPrefix) {
+ if (OldPrefix.empty() && NewPrefix.empty())
+ return;
+
+ StringRef OrigPath(Path.begin(), Path.size());
+ if (!OrigPath.startswith(OldPrefix))
+ return;
+
+ // If prefixes have the same size we can simply copy the new one over.
+ if (OldPrefix.size() == NewPrefix.size()) {
+ std::copy(NewPrefix.begin(), NewPrefix.end(), Path.begin());
+ return;
+ }
+
+ StringRef RelPath = OrigPath.substr(OldPrefix.size());
+ SmallString<256> NewPath;
+ path::append(NewPath, NewPrefix);
+ path::append(NewPath, RelPath);
+ Path.swap(NewPath);
+}
+
void native(const Twine &path, SmallVectorImpl<char> &result) {
assert((!path.isSingleStringRef() ||
path.getSingleStringRef().data() != result.data()) &&
@@ -1021,7 +1049,7 @@ file_magic identify_magic(StringRef Magic) {
case 0xCA:
if (Magic[1] == char(0xFE) && Magic[2] == char(0xBA) &&
- Magic[3] == char(0xBE)) {
+ (Magic[3] == char(0xBE) || Magic[3] == char(0xBF))) {
// This is complicated by an overlap with Java class files.
// See the Mach-O section in /usr/share/file/magic for details.
if (Magic.size() >= 8 && Magic[7] < 43)
@@ -1040,12 +1068,24 @@ file_magic identify_magic(StringRef Magic) {
Magic[2] == char(0xFA) &&
(Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) {
/* Native endian */
- if (Magic.size() >= 16) type = Magic[14] << 8 | Magic[15];
+ size_t MinSize;
+ if (Magic[3] == char(0xCE))
+ MinSize = sizeof(MachO::mach_header);
+ else
+ MinSize = sizeof(MachO::mach_header_64);
+ if (Magic.size() >= MinSize)
+ type = Magic[12] << 24 | Magic[13] << 12 | Magic[14] << 8 | Magic[15];
} else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) &&
Magic[1] == char(0xFA) && Magic[2] == char(0xED) &&
Magic[3] == char(0xFE)) {
/* Reverse endian */
- if (Magic.size() >= 14) type = Magic[13] << 8 | Magic[12];
+ size_t MinSize;
+ if (Magic[0] == char(0xCE))
+ MinSize = sizeof(MachO::mach_header);
+ else
+ MinSize = sizeof(MachO::mach_header_64);
+ if (Magic.size() >= MinSize)
+ type = Magic[15] << 24 | Magic[14] << 12 |Magic[13] << 8 | Magic[12];
}
switch (type) {
default: break;
OpenPOWER on IntegriCloud