aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-01-15 20:39:36 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-01-15 20:39:36 +0000
commit94b2ab3556a6b4f0f78720f494bdb4cff243c419 (patch)
tree082fa028191516fa1a8154daa6afaa4a8758f589 /llvm/lib/Support/Path.cpp
parentfff2517edcec21184fb86d3b48bed11885032587 (diff)
downloadllvm-94b2ab3556a6b4f0f78720f494bdb4cff243c419.zip
llvm-94b2ab3556a6b4f0f78720f494bdb4cff243c419.tar.gz
llvm-94b2ab3556a6b4f0f78720f494bdb4cff243c419.tar.bz2
Support/PathV2: Add identify_magic.
llvm-svn: 123548
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp57
1 files changed, 23 insertions, 34 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 4689208..e5e875b 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/Path.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Config/config.h"
#include "llvm/Support/FileSystem.h"
#include <cassert>
@@ -141,42 +142,33 @@ sys::IdentifyFileType(const char *magic, unsigned length) {
bool
Path::isArchive() const {
- std::string Magic;
- if (getMagicNumber(Magic, 8))
- if (IdentifyFileType(Magic.c_str(), Magic.length()) == Archive_FileType)
- return true;
- return false;
+ LLVMFileType type;
+ if (fs::identify_magic(str(), type))
+ return false;
+ return type == Archive_FileType;
}
bool
Path::isDynamicLibrary() const {
- std::string Magic;
- if (getMagicNumber(Magic, 64))
- switch (IdentifyFileType(Magic.c_str(),
- static_cast<unsigned>(Magic.length()))) {
- default: return false;
- case Mach_O_FixedVirtualMemorySharedLib_FileType:
- case Mach_O_DynamicallyLinkedSharedLib_FileType:
- case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
- case ELF_SharedObject_FileType:
- case COFF_FileType: return true;
- }
-
- return false;
+ LLVMFileType type;
+ if (fs::identify_magic(str(), type))
+ return false;
+ switch (type) {
+ default: return false;
+ case Mach_O_FixedVirtualMemorySharedLib_FileType:
+ case Mach_O_DynamicallyLinkedSharedLib_FileType:
+ case Mach_O_DynamicallyLinkedSharedLibStub_FileType:
+ case ELF_SharedObject_FileType:
+ case COFF_FileType: return true;
+ }
}
bool
Path::isObjectFile() const {
- std::string Magic;
- if (getMagicNumber(Magic, 64))
- if (IdentifyFileType(Magic.c_str(),
- static_cast<unsigned>(Magic.length()))
- != Unknown_FileType) {
- // Everything in LLVMFileType is currently an object file.
- return true;
- }
-
- return false;
+ LLVMFileType type;
+ if (fs::identify_magic(str(), type) || type == Unknown_FileType)
+ return false;
+ return true;
}
Path
@@ -210,13 +202,10 @@ Path::appendSuffix(StringRef suffix) {
bool
Path::isBitcodeFile() const {
- std::string actualMagic;
- if (!getMagicNumber(actualMagic, 4))
+ LLVMFileType type;
+ if (fs::identify_magic(str(), type))
return false;
- LLVMFileType FT =
- IdentifyFileType(actualMagic.c_str(),
- static_cast<unsigned>(actualMagic.length()));
- return FT == Bitcode_FileType;
+ return type == Bitcode_FileType;
}
bool Path::hasMagicNumber(StringRef Magic) const {